1 | // |
---|
2 | // LoggingConfigurator.h |
---|
3 | // |
---|
4 | // $Id: //poco/1.3/Util/include/Poco/Util/LoggingConfigurator.h#1 $ |
---|
5 | // |
---|
6 | // Library: Util |
---|
7 | // Package: Configuration |
---|
8 | // Module: LoggingConfigurator |
---|
9 | // |
---|
10 | // Definition of the LoggingConfigurator class. |
---|
11 | // |
---|
12 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. |
---|
13 | // and Contributors. |
---|
14 | // |
---|
15 | // Permission is hereby granted, free of charge, to any person or organization |
---|
16 | // obtaining a copy of the software and accompanying documentation covered by |
---|
17 | // this license (the "Software") to use, reproduce, display, distribute, |
---|
18 | // execute, and transmit the Software, and to prepare derivative works of the |
---|
19 | // Software, and to permit third-parties to whom the Software is furnished to |
---|
20 | // do so, all subject to the following: |
---|
21 | // |
---|
22 | // The copyright notices in the Software and this entire statement, including |
---|
23 | // the above license grant, this restriction and the following disclaimer, |
---|
24 | // must be included in all copies of the Software, in whole or in part, and |
---|
25 | // all derivative works of the Software, unless such copies or derivative |
---|
26 | // works are solely in the form of machine-executable object code generated by |
---|
27 | // a source language processor. |
---|
28 | // |
---|
29 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
30 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
31 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT |
---|
32 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE |
---|
33 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, |
---|
34 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
---|
35 | // DEALINGS IN THE SOFTWARE. |
---|
36 | // |
---|
37 | |
---|
38 | |
---|
39 | #ifndef Util_LoggingConfigurator_INCLUDED |
---|
40 | #define Util_LoggingConfigurator_INCLUDED |
---|
41 | |
---|
42 | |
---|
43 | #include "Poco/Util/Util.h" |
---|
44 | #include "Poco/Formatter.h" |
---|
45 | #include "Poco/Channel.h" |
---|
46 | |
---|
47 | |
---|
48 | namespace Poco { |
---|
49 | namespace Util { |
---|
50 | |
---|
51 | |
---|
52 | class AbstractConfiguration; |
---|
53 | |
---|
54 | |
---|
55 | class Util_API LoggingConfigurator |
---|
56 | /// This utility class uses a configuration object to configure the |
---|
57 | /// logging subsystem of an application. |
---|
58 | /// |
---|
59 | /// The LoggingConfigurator sets up and connects formatters, channels |
---|
60 | /// and loggers. To accomplish its work, the LoggingConfigurator relies on the |
---|
61 | /// functionality provided by the LoggingFactory und LoggingRegistry classes. |
---|
62 | /// |
---|
63 | /// The LoggingConfigurator expects all configuration data to be under a root |
---|
64 | /// property named "logging". |
---|
65 | /// |
---|
66 | /// Configuring Formatters |
---|
67 | /// |
---|
68 | /// A formatter is configured using the "logging.formatters" property. Every |
---|
69 | /// formatter has an internal name, which is only used for referring to it |
---|
70 | /// during configuration time. This name becomes part of the property name. |
---|
71 | /// Every formatter has a mandatory "class" property, which specifies the actual |
---|
72 | /// class implementing the formatter. Any other properties are passed on to |
---|
73 | /// the formatter by calling its setProperty() method. |
---|
74 | /// |
---|
75 | /// A typical formatter definition looks as follows: |
---|
76 | /// logging.formatters.f1.class = PatternFormatter |
---|
77 | /// logging.formatters.f1.pattern = %s: [%p] %t |
---|
78 | /// logging.formatters.f1.times = UTC |
---|
79 | /// |
---|
80 | /// Configuring Channels |
---|
81 | /// |
---|
82 | /// A channel is configured using the "logging.channels" property. Like with |
---|
83 | /// Formatters, every channel has an internal name, which is used during |
---|
84 | /// configuration only. The name becomes part of the property name. |
---|
85 | /// Every channel has a mandatory "class" property, which specifies the actual |
---|
86 | /// class implementing the channel. Any other properties are passed on to |
---|
87 | /// the formatter by calling its setProperty() method. |
---|
88 | /// |
---|
89 | /// For convenience, the "formatter" property of a channel is treated |
---|
90 | /// specifically. The "formatter" property can either be used to refer to |
---|
91 | /// an already defined formatter, or it can be used to specify an "inline" |
---|
92 | /// formatter definition. In either case, when a "formatter" property is |
---|
93 | /// present, the channel is automatically "wrapped" in a FormattingChannel |
---|
94 | /// object. |
---|
95 | /// |
---|
96 | /// Similarly, a channel supports also a "pattern" property, which results |
---|
97 | /// in the automatic instantiation of a FormattingChannel object with a |
---|
98 | /// connected PatternFormatter. |
---|
99 | /// |
---|
100 | /// Examples: |
---|
101 | /// logging.channels.c1.class = ConsoleChannel |
---|
102 | /// logging.channels.c1.formatter = f1 |
---|
103 | /// logging.channels.c2.class = FileChannel |
---|
104 | /// logging.channels.c2.path = ${system.tempDir}/sample.log |
---|
105 | /// logging.channels.c2.formatter.class = PatternFormatter |
---|
106 | /// logging.channels.c2.formatter.pattern = %s: [%p] %t |
---|
107 | /// logging.channels.c3.class = ConsoleChannel |
---|
108 | /// logging.channels.c3.pattern = %s: [%p] %t |
---|
109 | /// |
---|
110 | /// Configuring Loggers |
---|
111 | /// |
---|
112 | /// A logger is configured using the "logging.loggers" property. Like with |
---|
113 | /// channels and formatters, every logger has an internal name, which, however, |
---|
114 | /// is only used to ensure the uniqueness of the property names. Note that this |
---|
115 | /// name is different from the logger's full name, which is used to access |
---|
116 | /// the logger at runtime. |
---|
117 | /// Every logger except the root logger has a mandatory "name" property which |
---|
118 | /// is used to specify the logger's full name. |
---|
119 | /// Furthermore, a "channel" property is supported, which can either refer |
---|
120 | /// to a named channel, or which can contain an inline channel definition. |
---|
121 | /// |
---|
122 | /// Examples: |
---|
123 | /// logging.loggers.root.channel = c1 |
---|
124 | /// logging.loggers.root.level = warning |
---|
125 | /// logging.loggers.l1.name = logger1 |
---|
126 | /// logging.loggers.l1.channel.class = ConsoleChannel |
---|
127 | /// logging.loggers.l1.channel.pattern = %s: [%p] %t |
---|
128 | /// logging.loggers.l1.level = information |
---|
129 | { |
---|
130 | public: |
---|
131 | LoggingConfigurator(); |
---|
132 | /// Creates the LoggingConfigurator. |
---|
133 | |
---|
134 | ~LoggingConfigurator(); |
---|
135 | /// Destroys the LoggingConfigurator. |
---|
136 | |
---|
137 | void configure(AbstractConfiguration* pConfig); |
---|
138 | /// Configures the logging subsystem based on |
---|
139 | /// the given configuration. |
---|
140 | /// |
---|
141 | /// A ConfigurationView can be used to pass only |
---|
142 | /// a part of a larger configuration. |
---|
143 | |
---|
144 | private: |
---|
145 | void configureFormatters(AbstractConfiguration* pConfig); |
---|
146 | void configureChannels(AbstractConfiguration* pConfig); |
---|
147 | void configureLoggers(AbstractConfiguration* pConfig); |
---|
148 | Poco::Formatter* createFormatter(AbstractConfiguration* pConfig); |
---|
149 | Poco::Channel* createChannel(AbstractConfiguration* pConfig); |
---|
150 | void configureChannel(Channel* pChannel, AbstractConfiguration* pConfig); |
---|
151 | void configureLogger(AbstractConfiguration* pConfig); |
---|
152 | |
---|
153 | LoggingConfigurator(const LoggingConfigurator&); |
---|
154 | LoggingConfigurator& operator = (const LoggingConfigurator&); |
---|
155 | }; |
---|
156 | |
---|
157 | |
---|
158 | } } // namespace Poco::Util |
---|
159 | |
---|
160 | |
---|
161 | #endif // Util_LoggingConfigurator_INCLUDED |
---|