1 | // |
2 | // LoggingFactory.h |
3 | // |
4 | // Library: Foundation |
5 | // Package: Logging |
6 | // Module: LoggingFactory |
7 | // |
8 | // Definition of the LoggingFactory class. |
9 | // |
10 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. |
11 | // and Contributors. |
12 | // |
13 | // SPDX-License-Identifier: BSL-1.0 |
14 | // |
15 | |
16 | |
17 | #ifndef Foundation_LoggingFactory_INCLUDED |
18 | #define Foundation_LoggingFactory_INCLUDED |
19 | |
20 | |
21 | #include "Poco/Foundation.h" |
22 | #include "Poco/DynamicFactory.h" |
23 | #include "Poco/Channel.h" |
24 | #include "Poco/Formatter.h" |
25 | |
26 | |
27 | namespace Poco { |
28 | |
29 | |
30 | class Foundation_API LoggingFactory |
31 | /// An extensible factory for channels and formatters. |
32 | /// |
33 | /// The following channel classes are pre-registered: |
34 | /// - AsyncChannel |
35 | /// - ConsoleChannel |
36 | /// - EventLogChannel (Windows platforms only) |
37 | /// - FileChannel |
38 | /// - FormattingChannel |
39 | /// - NullChannel |
40 | /// - OpcomChannel (OpenVMS only) |
41 | /// - SplitterChannel |
42 | /// - SyslogChannel (Unix platforms only) |
43 | /// |
44 | /// The following formatter classes are pre-registered: |
45 | /// - PatternFormatter |
46 | { |
47 | public: |
48 | typedef AbstractInstantiator<Channel> ChannelInstantiator; |
49 | typedef AbstractInstantiator<Formatter> FormatterFactory; |
50 | |
51 | LoggingFactory(); |
52 | /// Creates the LoggingFactory. |
53 | /// |
54 | /// Automatically registers class factories for the |
55 | /// built-in channel and formatter classes. |
56 | |
57 | ~LoggingFactory(); |
58 | /// Destroys the LoggingFactory. |
59 | |
60 | void registerChannelClass(const std::string& className, ChannelInstantiator* pFactory); |
61 | /// Registers a channel class with the LoggingFactory. |
62 | |
63 | void registerFormatterClass(const std::string& className, FormatterFactory* pFactory); |
64 | /// Registers a formatter class with the LoggingFactory. |
65 | |
66 | Channel* createChannel(const std::string& className) const; |
67 | /// Creates a new Channel instance from specified class. |
68 | /// |
69 | /// Throws a NotFoundException if the specified channel class |
70 | /// has not been registered. |
71 | |
72 | Formatter* createFormatter(const std::string& className) const; |
73 | /// Creates a new Formatter instance from specified class. |
74 | /// |
75 | /// Throws a NotFoundException if the specified formatter class |
76 | /// has not been registered. |
77 | |
78 | static LoggingFactory& defaultFactory(); |
79 | /// Returns a reference to the default |
80 | /// LoggingFactory. |
81 | |
82 | private: |
83 | void registerBuiltins(); |
84 | |
85 | DynamicFactory<Channel> _channelFactory; |
86 | DynamicFactory<Formatter> _formatterFactory; |
87 | }; |
88 | |
89 | |
90 | } // namespace Poco |
91 | |
92 | |
93 | #endif // Foundation_LoggingFactory_INCLUDED |
94 | |