1 | // |
2 | // Logger.h |
3 | // |
4 | // Library: Foundation |
5 | // Package: Logging |
6 | // Module: Logger |
7 | // |
8 | // Definition of the Logger class. |
9 | // |
10 | // Copyright (c) 2004-2010, Applied Informatics Software Engineering GmbH. |
11 | // and Contributors. |
12 | // |
13 | // SPDX-License-Identifier: BSL-1.0 |
14 | // |
15 | |
16 | |
17 | #ifndef Foundation_Logger_INCLUDED |
18 | #define Foundation_Logger_INCLUDED |
19 | |
20 | |
21 | #include "Poco/Foundation.h" |
22 | #include "Poco/Channel.h" |
23 | #include "Poco/Message.h" |
24 | #include "Poco/Format.h" |
25 | #include <map> |
26 | #include <vector> |
27 | #include <cstddef> |
28 | #include <atomic> |
29 | |
30 | |
31 | namespace Poco { |
32 | |
33 | |
34 | class Exception; |
35 | |
36 | |
37 | class Foundation_API Logger: public Channel |
38 | /// Logger is a special Channel that acts as the main |
39 | /// entry point into the logging framework. |
40 | /// |
41 | /// An application uses instances of the Logger class to generate its log messages |
42 | /// and send them on their way to their final destination. Logger instances |
43 | /// are organized in a hierarchical, tree-like manner and are maintained by |
44 | /// the framework. Every Logger object has exactly one direct ancestor, with |
45 | /// the exception of the root logger. A newly created logger inherits its properties - |
46 | /// channel and level - from its direct ancestor. Every logger is connected |
47 | /// to a channel, to which it passes on its messages. Furthermore, every logger |
48 | /// has a log level, which is used for filtering messages based on their priority. |
49 | /// Only messages with a priority equal to or higher than the specified level |
50 | /// are passed on. For example, if the level of a logger is set to three (PRIO_ERROR), |
51 | /// only messages with priority PRIO_ERROR, PRIO_CRITICAL and PRIO_FATAL will |
52 | /// propagate. If the level is set to zero, the logger is effectively disabled. |
53 | /// |
54 | /// The name of a logger determines the logger's place within the logger hierarchy. |
55 | /// The name of the root logger is always "", the empty string. For all other |
56 | /// loggers, the name is made up of one or more components, separated by a period. |
57 | /// For example, the loggers with the name HTTPServer.RequestHandler and HTTPServer.Listener |
58 | /// are descendants of the logger HTTPServer, which itself is a descendant of |
59 | /// the root logger. There is not limit as to how deep |
60 | /// the logger hierarchy can become. Once a logger has been created and it has |
61 | /// inherited the channel and level from its ancestor, it loses the connection |
62 | /// to it. So changes to the level or channel of a logger do not affect its |
63 | /// descendants. This greatly simplifies the implementation of the framework |
64 | /// and is no real restriction, because almost always levels and channels are |
65 | /// set up at application startup and never changed afterwards. Nevertheless, |
66 | /// there are methods to simultaneously change the level and channel of all |
67 | /// loggers in a certain hierarchy. |
68 | /// |
69 | /// There are also convenience macros available that wrap the actual |
70 | /// logging statement into a check whether the Logger's log level |
71 | /// is sufficient to actually log the message. This allows to increase |
72 | /// the application performance if many complex log statements |
73 | /// are used. The macros also add the source file path and line |
74 | /// number into the log message so that it is available to formatters. |
75 | /// Variants of these macros that allow message formatting with Poco::format() |
76 | /// are also available. Up to four arguments are supported. |
77 | /// |
78 | /// Examples: |
79 | /// poco_warning(logger, "This is a warning"); |
80 | /// poco_information_f2(logger, "An informational message with args: %d, %d", 1, 2); |
81 | { |
82 | public: |
83 | const std::string& name() const; |
84 | /// Returns the name of the logger, which is set as the |
85 | /// message source on all messages created by the logger. |
86 | |
87 | void setChannel(Channel* pChannel); |
88 | /// Attaches the given Channel to the Logger. |
89 | |
90 | Channel* getChannel() const; |
91 | /// Returns the Channel attached to the logger. |
92 | |
93 | void setLevel(int level); |
94 | /// Sets the Logger's log level. |
95 | /// |
96 | /// See Message::Priority for valid log levels. |
97 | /// Setting the log level to zero turns off |
98 | /// logging for that Logger. |
99 | |
100 | int getLevel() const; |
101 | /// Returns the Logger's log level. |
102 | |
103 | void setLevel(const std::string& level); |
104 | /// Sets the Logger's log level using a symbolic value. |
105 | /// |
106 | /// Valid values are: |
107 | /// - none (turns off logging) |
108 | /// - fatal |
109 | /// - critical |
110 | /// - error |
111 | /// - warning |
112 | /// - notice |
113 | /// - information |
114 | /// - debug |
115 | /// - trace |
116 | |
117 | void setProperty(const std::string& name, const std::string& value); |
118 | /// Sets or changes a configuration property. |
119 | /// |
120 | /// Only the "channel" and "level" properties are supported, which allow |
121 | /// setting the target channel and log level, respectively, via the LoggingRegistry. |
122 | /// The "channel" and "level" properties are set-only. |
123 | |
124 | void log(const Message& msg); |
125 | /// Logs the given message if its priority is |
126 | /// greater than or equal to the Logger's log level. |
127 | |
128 | void log(const Exception& exc); |
129 | /// Logs the given exception with priority PRIO_ERROR. |
130 | |
131 | void log(const Exception& exc, const char* file, int line); |
132 | /// Logs the given exception with priority PRIO_ERROR. |
133 | /// |
134 | /// File must be a static string, such as the value of |
135 | /// the __FILE__ macro. The string is not copied |
136 | /// internally for performance reasons. |
137 | |
138 | void fatal(const std::string& msg); |
139 | /// If the Logger's log level is at least PRIO_FATAL, |
140 | /// creates a Message with priority PRIO_FATAL |
141 | /// and the given message text and sends it |
142 | /// to the attached channel. |
143 | |
144 | void fatal(const std::string& msg, const char* file, int line); |
145 | /// If the Logger's log level is at least PRIO_FATAL, |
146 | /// creates a Message with priority PRIO_FATAL |
147 | /// and the given message text and sends it |
148 | /// to the attached channel. |
149 | /// |
150 | /// File must be a static string, such as the value of |
151 | /// the __FILE__ macro. The string is not copied |
152 | /// internally for performance reasons. |
153 | |
154 | template <typename T, typename... Args> |
155 | void fatal(const std::string &fmt, T arg1, Args&&... args) |
156 | { |
157 | log(Poco::format(fmt, arg1, std::forward<Args>(args)...), Message::PRIO_FATAL); |
158 | } |
159 | |
160 | void critical(const std::string& msg); |
161 | /// If the Logger's log level is at least PRIO_CRITICAL, |
162 | /// creates a Message with priority PRIO_CRITICAL |
163 | /// and the given message text and sends it |
164 | /// to the attached channel. |
165 | |
166 | void critical(const std::string& msg, const char* file, int line); |
167 | /// If the Logger's log level is at least PRIO_CRITICAL, |
168 | /// creates a Message with priority PRIO_CRITICAL |
169 | /// and the given message text and sends it |
170 | /// to the attached channel. |
171 | /// |
172 | /// File must be a static string, such as the value of |
173 | /// the __FILE__ macro. The string is not copied |
174 | /// internally for performance reasons. |
175 | |
176 | template <typename T, typename... Args> |
177 | void critical(const std::string &fmt, T arg1, Args&&... args) |
178 | { |
179 | log(Poco::format(fmt, arg1, std::forward<Args>(args)...), Message::PRIO_CRITICAL); |
180 | } |
181 | |
182 | void error(const std::string& msg); |
183 | /// If the Logger's log level is at least PRIO_ERROR, |
184 | /// creates a Message with priority PRIO_ERROR |
185 | /// and the given message text and sends it |
186 | /// to the attached channel. |
187 | |
188 | void error(const std::string& msg, const char* file, int line); |
189 | /// If the Logger's log level is at least PRIO_ERROR, |
190 | /// creates a Message with priority PRIO_ERROR |
191 | /// and the given message text and sends it |
192 | /// to the attached channel. |
193 | /// |
194 | /// File must be a static string, such as the value of |
195 | /// the __FILE__ macro. The string is not copied |
196 | /// internally for performance reasons. |
197 | |
198 | template <typename T, typename... Args> |
199 | void error(const std::string &fmt, T arg1, Args&&... args) |
200 | { |
201 | log(Poco::format(fmt, arg1, std::forward<Args>(args)...), Message::PRIO_ERROR); |
202 | } |
203 | |
204 | void warning(const std::string& msg); |
205 | /// If the Logger's log level is at least PRIO_WARNING, |
206 | /// creates a Message with priority PRIO_WARNING |
207 | /// and the given message text and sends it |
208 | /// to the attached channel. |
209 | |
210 | void warning(const std::string& msg, const char* file, int line); |
211 | /// If the Logger's log level is at least PRIO_WARNING, |
212 | /// creates a Message with priority PRIO_WARNING |
213 | /// and the given message text and sends it |
214 | /// to the attached channel. |
215 | /// |
216 | /// File must be a static string, such as the value of |
217 | /// the __FILE__ macro. The string is not copied |
218 | /// internally for performance reasons. |
219 | |
220 | template <typename T, typename... Args> |
221 | void warning(const std::string &fmt, T arg1, Args&&... args) |
222 | { |
223 | log(Poco::format(fmt, arg1, std::forward<Args>(args)...), Message::PRIO_WARNING); |
224 | } |
225 | |
226 | void notice(const std::string& msg); |
227 | /// If the Logger's log level is at least PRIO_NOTICE, |
228 | /// creates a Message with priority PRIO_NOTICE |
229 | /// and the given message text and sends it |
230 | /// to the attached channel. |
231 | |
232 | void notice(const std::string& msg, const char* file, int line); |
233 | /// If the Logger's log level is at least PRIO_NOTICE, |
234 | /// creates a Message with priority PRIO_NOTICE |
235 | /// and the given message text and sends it |
236 | /// to the attached channel. |
237 | /// |
238 | /// File must be a static string, such as the value of |
239 | /// the __FILE__ macro. The string is not copied |
240 | /// internally for performance reasons. |
241 | |
242 | template <typename T, typename... Args> |
243 | void notice(const std::string &fmt, T arg1, Args&&... args) |
244 | { |
245 | log(Poco::format(fmt, arg1, std::forward<Args>(args)...), Message::PRIO_NOTICE); |
246 | } |
247 | |
248 | void information(const std::string& msg); |
249 | /// If the Logger's log level is at least PRIO_INFORMATION, |
250 | /// creates a Message with priority PRIO_INFORMATION |
251 | /// and the given message text and sends it |
252 | /// to the attached channel. |
253 | |
254 | void information(const std::string& msg, const char* file, int line); |
255 | /// If the Logger's log level is at least PRIO_INFORMATION, |
256 | /// creates a Message with priority PRIO_INFORMATION |
257 | /// and the given message text and sends it |
258 | /// to the attached channel. |
259 | /// |
260 | /// File must be a static string, such as the value of |
261 | /// the __FILE__ macro. The string is not copied |
262 | /// internally for performance reasons. |
263 | |
264 | template <typename T, typename... Args> |
265 | void information(const std::string &fmt, T arg1, Args&&... args) |
266 | { |
267 | log(Poco::format(fmt, arg1, std::forward<Args>(args)...), Message::PRIO_INFORMATION); |
268 | } |
269 | |
270 | void debug(const std::string& msg); |
271 | /// If the Logger's log level is at least PRIO_DEBUG, |
272 | /// creates a Message with priority PRIO_DEBUG |
273 | /// and the given message text and sends it |
274 | /// to the attached channel. |
275 | |
276 | void debug(const std::string& msg, const char* file, int line); |
277 | /// If the Logger's log level is at least PRIO_DEBUG, |
278 | /// creates a Message with priority PRIO_DEBUG |
279 | /// and the given message text and sends it |
280 | /// to the attached channel. |
281 | /// |
282 | /// File must be a static string, such as the value of |
283 | /// the __FILE__ macro. The string is not copied |
284 | /// internally for performance reasons. |
285 | |
286 | template <typename T, typename... Args> |
287 | void debug(const std::string &fmt, T arg1, Args&&... args) |
288 | { |
289 | log(Poco::format(fmt, arg1, std::forward<Args>(args)...), Message::PRIO_DEBUG); |
290 | } |
291 | |
292 | void trace(const std::string& msg); |
293 | /// If the Logger's log level is at least PRIO_TRACE, |
294 | /// creates a Message with priority PRIO_TRACE |
295 | /// and the given message text and sends it |
296 | /// to the attached channel. |
297 | |
298 | void trace(const std::string& msg, const char* file, int line); |
299 | /// If the Logger's log level is at least PRIO_TRACE, |
300 | /// creates a Message with priority PRIO_TRACE |
301 | /// and the given message text and sends it |
302 | /// to the attached channel. |
303 | /// |
304 | /// File must be a static string, such as the value of |
305 | /// the __FILE__ macro. The string is not copied |
306 | /// internally for performance reasons. |
307 | |
308 | template <typename T, typename... Args> |
309 | void trace(const std::string &fmt, T arg1, Args&&... args) |
310 | { |
311 | log(Poco::format(fmt, arg1, std::forward<Args>(args)...), Message::PRIO_TRACE); |
312 | } |
313 | |
314 | void dump(const std::string& msg, const void* buffer, std::size_t length, Message::Priority prio = Message::PRIO_DEBUG); |
315 | /// Logs the given message, followed by the data in buffer. |
316 | /// |
317 | /// The data in buffer is written in canonical hex+ASCII form: |
318 | /// Offset (4 bytes) in hexadecimal, followed by sixteen |
319 | /// space-separated, two column, hexadecimal bytes, |
320 | /// followed by the same sixteen bytes as ASCII characters. |
321 | /// For bytes outside the range 32 .. 127, a dot is printed. |
322 | |
323 | bool is(int level) const; |
324 | /// Returns true if at least the given log level is set. |
325 | |
326 | bool fatal() const; |
327 | /// Returns true if the log level is at least PRIO_FATAL. |
328 | |
329 | bool critical() const; |
330 | /// Returns true if the log level is at least PRIO_CRITICAL. |
331 | |
332 | bool error() const; |
333 | /// Returns true if the log level is at least PRIO_ERROR. |
334 | |
335 | bool warning() const; |
336 | /// Returns true if the log level is at least PRIO_WARNING. |
337 | |
338 | bool notice() const; |
339 | /// Returns true if the log level is at least PRIO_NOTICE. |
340 | |
341 | bool information() const; |
342 | /// Returns true if the log level is at least PRIO_INFORMATION. |
343 | |
344 | bool debug() const; |
345 | /// Returns true if the log level is at least PRIO_DEBUG. |
346 | |
347 | bool trace() const; |
348 | /// Returns true if the log level is at least PRIO_TRACE. |
349 | |
350 | static std::string format(const std::string& fmt, const std::string& arg); |
351 | /// Replaces all occurrences of $0 in fmt with the string given in arg and |
352 | /// returns the result. To include a dollar sign in the result string, |
353 | /// specify two dollar signs ($$) in the format string. |
354 | |
355 | static std::string format(const std::string& fmt, const std::string& arg0, const std::string& arg1); |
356 | /// Replaces all occurrences of $<n> in fmt with the string given in arg<n> and |
357 | /// returns the result. To include a dollar sign in the result string, |
358 | /// specify two dollar signs ($$) in the format string. |
359 | |
360 | static std::string format(const std::string& fmt, const std::string& arg0, const std::string& arg1, const std::string& arg2); |
361 | /// Replaces all occurrences of $<n> in fmt with the string given in arg<n> and |
362 | /// returns the result. To include a dollar sign in the result string, |
363 | /// specify two dollar signs ($$) in the format string. |
364 | |
365 | static std::string format(const std::string& fmt, const std::string& arg0, const std::string& arg1, const std::string& arg2, const std::string& arg3); |
366 | /// Replaces all occurrences of $<n> in fmt with the string given in arg<n> and |
367 | /// returns the result. To include a dollar sign in the result string, |
368 | /// specify two dollar signs ($$) in the format string. |
369 | |
370 | static void formatDump(std::string& message, const void* buffer, std::size_t length); |
371 | /// Creates a hex-dump of the given buffer and appends it to the |
372 | /// given message string. |
373 | |
374 | static void setLevel(const std::string& name, int level); |
375 | /// Sets the given log level on all loggers that are |
376 | /// descendants of the Logger with the given name. |
377 | |
378 | static void setChannel(const std::string& name, Channel* pChannel); |
379 | /// Attaches the given Channel to all loggers that are |
380 | /// descendants of the Logger with the given name. |
381 | |
382 | static void setProperty(const std::string& loggerName, const std::string& propertyName, const std::string& value); |
383 | /// Sets or changes a configuration property for all loggers |
384 | /// that are descendants of the Logger with the given name. |
385 | |
386 | static Logger& get(const std::string& name); |
387 | /// Returns a reference to the Logger with the given name. |
388 | /// If the Logger does not yet exist, it is created, based |
389 | /// on its parent logger. |
390 | |
391 | static Logger& unsafeGet(const std::string& name); |
392 | /// Returns a reference to the Logger with the given name. |
393 | /// If the Logger does not yet exist, it is created, based |
394 | /// on its parent logger. |
395 | /// |
396 | /// WARNING: This method is not thread safe. You should |
397 | /// probably use get() instead. |
398 | /// The only time this method should be used is during |
399 | /// program initialization, when only one thread is running. |
400 | |
401 | static Logger& create(const std::string& name, Channel* pChannel, int level = Message::PRIO_INFORMATION); |
402 | /// Creates and returns a reference to a Logger with the |
403 | /// given name. The Logger's Channel and log level as set as |
404 | /// specified. |
405 | |
406 | static Logger& root(); |
407 | /// Returns a reference to the root logger, which is the ultimate |
408 | /// ancestor of all Loggers. |
409 | |
410 | static Logger* has(const std::string& name); |
411 | /// Returns a pointer to the Logger with the given name if it |
412 | /// exists, or a null pointer otherwise. |
413 | |
414 | static void destroy(const std::string& name); |
415 | /// Destroys the logger with the specified name. Does nothing |
416 | /// if the logger is not found. |
417 | /// |
418 | /// After a logger has been destroyed, all references to it |
419 | /// become invalid. |
420 | |
421 | static void shutdown(); |
422 | /// Shuts down the logging framework and releases all |
423 | /// Loggers. |
424 | |
425 | static void names(std::vector<std::string>& names); |
426 | /// Fills the given vector with the names |
427 | /// of all currently defined loggers. |
428 | |
429 | static int parseLevel(const std::string& level); |
430 | /// Parses a symbolic log level from a string and |
431 | /// returns the resulting numeric level. |
432 | /// |
433 | /// Valid symbolic levels are: |
434 | /// - none (turns off logging) |
435 | /// - fatal |
436 | /// - critical |
437 | /// - error |
438 | /// - warning |
439 | /// - notice |
440 | /// - information |
441 | /// - debug |
442 | /// - trace |
443 | /// |
444 | /// The level is not case sensitive. |
445 | |
446 | static const std::string ROOT; /// The name of the root logger (""). |
447 | |
448 | protected: |
449 | typedef std::map<std::string, Logger*> LoggerMap; |
450 | |
451 | Logger(const std::string& name, Channel* pChannel, int level); |
452 | ~Logger(); |
453 | |
454 | void log(const std::string& text, Message::Priority prio); |
455 | void log(const std::string& text, Message::Priority prio, const char* file, int line); |
456 | |
457 | static std::string format(const std::string& fmt, int argc, std::string argv[]); |
458 | static Logger& parent(const std::string& name); |
459 | static void add(Logger* pLogger); |
460 | static Logger* find(const std::string& name); |
461 | |
462 | private: |
463 | Logger(); |
464 | Logger(const Logger&); |
465 | Logger& operator = (const Logger&); |
466 | |
467 | std::string _name; |
468 | Channel* _pChannel; |
469 | std::atomic_int _level; |
470 | |
471 | static LoggerMap* _pLoggerMap; |
472 | static Mutex _mapMtx; |
473 | }; |
474 | |
475 | |
476 | // |
477 | // convenience macros |
478 | // |
479 | #define poco_fatal(logger, msg) \ |
480 | if ((logger).fatal()) (logger).fatal(msg, __FILE__, __LINE__); else (void) 0 |
481 | |
482 | #define poco_fatal_f1(logger, fmt, arg1) \ |
483 | if ((logger).fatal()) (logger).fatal(Poco::format((fmt), arg1), __FILE__, __LINE__); else (void) 0 |
484 | |
485 | #define poco_fatal_f2(logger, fmt, arg1, arg2) \ |
486 | if ((logger).fatal()) (logger).fatal(Poco::format((fmt), (arg1), (arg2)), __FILE__, __LINE__); else (void) 0 |
487 | |
488 | #define poco_fatal_f3(logger, fmt, arg1, arg2, arg3) \ |
489 | if ((logger).fatal()) (logger).fatal(Poco::format((fmt), (arg1), (arg2), (arg3)), __FILE__, __LINE__); else (void) 0 |
490 | |
491 | #define poco_fatal_f4(logger, fmt, arg1, arg2, arg3, arg4) \ |
492 | if ((logger).fatal()) (logger).fatal(Poco::format((fmt), (arg1), (arg2), (arg3), (arg4)), __FILE__, __LINE__); else (void) 0 |
493 | |
494 | #define poco_critical(logger, msg) \ |
495 | if ((logger).critical()) (logger).critical(msg, __FILE__, __LINE__); else (void) 0 |
496 | |
497 | #define poco_critical_f1(logger, fmt, arg1) \ |
498 | if ((logger).critical()) (logger).critical(Poco::format((fmt), (arg1)), __FILE__, __LINE__); else (void) 0 |
499 | |
500 | #define poco_critical_f2(logger, fmt, arg1, arg2) \ |
501 | if ((logger).critical()) (logger).critical(Poco::format((fmt), (arg1), (arg2)), __FILE__, __LINE__); else (void) 0 |
502 | |
503 | #define poco_critical_f3(logger, fmt, arg1, arg2, arg3) \ |
504 | if ((logger).critical()) (logger).critical(Poco::format((fmt), (arg1), (arg2), (arg3)), __FILE__, __LINE__); else (void) 0 |
505 | |
506 | #define poco_critical_f4(logger, fmt, arg1, arg2, arg3, arg4) \ |
507 | if ((logger).critical()) (logger).critical(Poco::format((fmt), (arg1), (arg2), (arg3), (arg4)), __FILE__, __LINE__); else (void) 0 |
508 | |
509 | #define poco_error(logger, msg) \ |
510 | if ((logger).error()) (logger).error(msg, __FILE__, __LINE__); else (void) 0 |
511 | |
512 | #define poco_error_f1(logger, fmt, arg1) \ |
513 | if ((logger).error()) (logger).error(Poco::format((fmt), (arg1)), __FILE__, __LINE__); else (void) 0 |
514 | |
515 | #define poco_error_f2(logger, fmt, arg1, arg2) \ |
516 | if ((logger).error()) (logger).error(Poco::format((fmt), (arg1), (arg2)), __FILE__, __LINE__); else (void) 0 |
517 | |
518 | #define poco_error_f3(logger, fmt, arg1, arg2, arg3) \ |
519 | if ((logger).error()) (logger).error(Poco::format((fmt), (arg1), (arg2), (arg3)), __FILE__, __LINE__); else (void) 0 |
520 | |
521 | #define poco_error_f4(logger, fmt, arg1, arg2, arg3, arg4) \ |
522 | if ((logger).error()) (logger).error(Poco::format((fmt), (arg1), (arg2), (arg3), (arg4)), __FILE__, __LINE__); else (void) 0 |
523 | |
524 | #define poco_warning(logger, msg) \ |
525 | if ((logger).warning()) (logger).warning(msg, __FILE__, __LINE__); else (void) 0 |
526 | |
527 | #define poco_warning_f1(logger, fmt, arg1) \ |
528 | if ((logger).warning()) (logger).warning(Poco::format((fmt), (arg1)), __FILE__, __LINE__); else (void) 0 |
529 | |
530 | #define poco_warning_f2(logger, fmt, arg1, arg2) \ |
531 | if ((logger).warning()) (logger).warning(Poco::format((fmt), (arg1), (arg2)), __FILE__, __LINE__); else (void) 0 |
532 | |
533 | #define poco_warning_f3(logger, fmt, arg1, arg2, arg3) \ |
534 | if ((logger).warning()) (logger).warning(Poco::format((fmt), (arg1), (arg2), (arg3)), __FILE__, __LINE__); else (void) 0 |
535 | |
536 | #define poco_warning_f4(logger, fmt, arg1, arg2, arg3, arg4) \ |
537 | if ((logger).warning()) (logger).warning(Poco::format((fmt), (arg1), (arg2), (arg3), (arg4)), __FILE__, __LINE__); else (void) 0 |
538 | |
539 | #define poco_notice(logger, msg) \ |
540 | if ((logger).notice()) (logger).notice(msg, __FILE__, __LINE__); else (void) 0 |
541 | |
542 | #define poco_notice_f1(logger, fmt, arg1) \ |
543 | if ((logger).notice()) (logger).notice(Poco::format((fmt), (arg1)), __FILE__, __LINE__); else (void) 0 |
544 | |
545 | #define poco_notice_f2(logger, fmt, arg1, arg2) \ |
546 | if ((logger).notice()) (logger).notice(Poco::format((fmt), (arg1), (arg2)), __FILE__, __LINE__); else (void) 0 |
547 | |
548 | #define poco_notice_f3(logger, fmt, arg1, arg2, arg3) \ |
549 | if ((logger).notice()) (logger).notice(Poco::format((fmt), (arg1), (arg2), (arg3)), __FILE__, __LINE__); else (void) 0 |
550 | |
551 | #define poco_notice_f4(logger, fmt, arg1, arg2, arg3, arg4) \ |
552 | if ((logger).notice()) (logger).notice(Poco::format((fmt), (arg1), (arg2), (arg3), (arg4)), __FILE__, __LINE__); else (void) 0 |
553 | |
554 | #define poco_information(logger, msg) \ |
555 | if ((logger).information()) (logger).information(msg, __FILE__, __LINE__); else (void) 0 |
556 | |
557 | #define poco_information_f1(logger, fmt, arg1) \ |
558 | if ((logger).information()) (logger).information(Poco::format((fmt), (arg1)), __FILE__, __LINE__); else (void) 0 |
559 | |
560 | #define poco_information_f2(logger, fmt, arg1, arg2) \ |
561 | if ((logger).information()) (logger).information(Poco::format((fmt), (arg1), (arg2)), __FILE__, __LINE__); else (void) 0 |
562 | |
563 | #define poco_information_f3(logger, fmt, arg1, arg2, arg3) \ |
564 | if ((logger).information()) (logger).information(Poco::format((fmt), (arg1), (arg2), (arg3)), __FILE__, __LINE__); else (void) 0 |
565 | |
566 | #define poco_information_f4(logger, fmt, arg1, arg2, arg3, arg4) \ |
567 | if ((logger).information()) (logger).information(Poco::format((fmt), (arg1), (arg2), (arg3), (arg4)), __FILE__, __LINE__); else (void) 0 |
568 | |
569 | #define poco_debug(logger, msg) \ |
570 | if ((logger).debug()) (logger).debug(msg, __FILE__, __LINE__); else (void) 0 |
571 | |
572 | #define poco_debug_f1(logger, fmt, arg1) \ |
573 | if ((logger).debug()) (logger).debug(Poco::format((fmt), (arg1)), __FILE__, __LINE__); else (void) 0 |
574 | |
575 | #define poco_debug_f2(logger, fmt, arg1, arg2) \ |
576 | if ((logger).debug()) (logger).debug(Poco::format((fmt), (arg1), (arg2)), __FILE__, __LINE__); else (void) 0 |
577 | |
578 | #define poco_debug_f3(logger, fmt, arg1, arg2, arg3) \ |
579 | if ((logger).debug()) (logger).debug(Poco::format((fmt), (arg1), (arg2), (arg3)), __FILE__, __LINE__); else (void) 0 |
580 | |
581 | #define poco_debug_f4(logger, fmt, arg1, arg2, arg3, arg4) \ |
582 | if ((logger).debug()) (logger).debug(Poco::format((fmt), (arg1), (arg2), (arg3), (arg4)), __FILE__, __LINE__); else (void) 0 |
583 | |
584 | #define poco_trace(logger, msg) \ |
585 | if ((logger).trace()) (logger).trace(msg, __FILE__, __LINE__); else (void) 0 |
586 | |
587 | #define poco_trace_f1(logger, fmt, arg1) \ |
588 | if ((logger).trace()) (logger).trace(Poco::format((fmt), (arg1)), __FILE__, __LINE__); else (void) 0 |
589 | |
590 | #define poco_trace_f2(logger, fmt, arg1, arg2) \ |
591 | if ((logger).trace()) (logger).trace(Poco::format((fmt), (arg1), (arg2)), __FILE__, __LINE__); else (void) 0 |
592 | |
593 | #define poco_trace_f3(logger, fmt, arg1, arg2, arg3) \ |
594 | if ((logger).trace()) (logger).trace(Poco::format((fmt), (arg1), (arg2), (arg3)), __FILE__, __LINE__); else (void) 0 |
595 | |
596 | #define poco_trace_f4(logger, fmt, arg1, arg2, arg3, arg4) \ |
597 | if ((logger).trace()) (logger).trace(Poco::format((fmt), (arg1), (arg2), (arg3), (arg4)), __FILE__, __LINE__); else (void) 0 |
598 | |
599 | |
600 | // |
601 | // inlines |
602 | // |
603 | inline const std::string& Logger::name() const |
604 | { |
605 | return _name; |
606 | } |
607 | |
608 | |
609 | inline int Logger::getLevel() const |
610 | { |
611 | return _level; |
612 | } |
613 | |
614 | |
615 | inline void Logger::log(const std::string& text, Message::Priority prio) |
616 | { |
617 | if (_level >= prio && _pChannel) |
618 | { |
619 | _pChannel->log(Message(_name, text, prio)); |
620 | } |
621 | } |
622 | |
623 | |
624 | inline void Logger::log(const std::string& text, Message::Priority prio, const char* file, int line) |
625 | { |
626 | if (_level >= prio && _pChannel) |
627 | { |
628 | _pChannel->log(Message(_name, text, prio, file, line)); |
629 | } |
630 | } |
631 | |
632 | |
633 | inline void Logger::fatal(const std::string& msg) |
634 | { |
635 | log(msg, Message::PRIO_FATAL); |
636 | } |
637 | |
638 | |
639 | inline void Logger::fatal(const std::string& msg, const char* file, int line) |
640 | { |
641 | log(msg, Message::PRIO_FATAL, file, line); |
642 | } |
643 | |
644 | |
645 | |
646 | inline void Logger::critical(const std::string& msg) |
647 | { |
648 | log(msg, Message::PRIO_CRITICAL); |
649 | } |
650 | |
651 | |
652 | inline void Logger::critical(const std::string& msg, const char* file, int line) |
653 | { |
654 | log(msg, Message::PRIO_CRITICAL, file, line); |
655 | } |
656 | |
657 | |
658 | inline void Logger::error(const std::string& msg) |
659 | { |
660 | log(msg, Message::PRIO_ERROR); |
661 | } |
662 | |
663 | |
664 | inline void Logger::error(const std::string& msg, const char* file, int line) |
665 | { |
666 | log(msg, Message::PRIO_ERROR, file, line); |
667 | } |
668 | |
669 | |
670 | inline void Logger::warning(const std::string& msg) |
671 | { |
672 | log(msg, Message::PRIO_WARNING); |
673 | } |
674 | |
675 | |
676 | inline void Logger::warning(const std::string& msg, const char* file, int line) |
677 | { |
678 | log(msg, Message::PRIO_WARNING, file, line); |
679 | } |
680 | |
681 | |
682 | inline void Logger::notice(const std::string& msg) |
683 | { |
684 | log(msg, Message::PRIO_NOTICE); |
685 | } |
686 | |
687 | |
688 | inline void Logger::notice(const std::string& msg, const char* file, int line) |
689 | { |
690 | log(msg, Message::PRIO_NOTICE, file, line); |
691 | } |
692 | |
693 | |
694 | inline void Logger::information(const std::string& msg) |
695 | { |
696 | log(msg, Message::PRIO_INFORMATION); |
697 | } |
698 | |
699 | |
700 | inline void Logger::information(const std::string& msg, const char* file, int line) |
701 | { |
702 | log(msg, Message::PRIO_INFORMATION, file, line); |
703 | } |
704 | |
705 | |
706 | inline void Logger::debug(const std::string& msg) |
707 | { |
708 | log(msg, Message::PRIO_DEBUG); |
709 | } |
710 | |
711 | |
712 | inline void Logger::debug(const std::string& msg, const char* file, int line) |
713 | { |
714 | log(msg, Message::PRIO_DEBUG, file, line); |
715 | } |
716 | |
717 | |
718 | inline void Logger::trace(const std::string& msg) |
719 | { |
720 | log(msg, Message::PRIO_TRACE); |
721 | } |
722 | |
723 | |
724 | inline void Logger::trace(const std::string& msg, const char* file, int line) |
725 | { |
726 | log(msg, Message::PRIO_TRACE, file, line); |
727 | } |
728 | |
729 | |
730 | inline bool Logger::is(int level) const |
731 | { |
732 | return _level >= level; |
733 | } |
734 | |
735 | |
736 | inline bool Logger::fatal() const |
737 | { |
738 | return _level >= Message::PRIO_FATAL; |
739 | } |
740 | |
741 | |
742 | inline bool Logger::critical() const |
743 | { |
744 | return _level >= Message::PRIO_CRITICAL; |
745 | } |
746 | |
747 | |
748 | inline bool Logger::error() const |
749 | { |
750 | return _level >= Message::PRIO_ERROR; |
751 | } |
752 | |
753 | |
754 | inline bool Logger::warning() const |
755 | { |
756 | return _level >= Message::PRIO_WARNING; |
757 | } |
758 | |
759 | |
760 | inline bool Logger::notice() const |
761 | { |
762 | return _level >= Message::PRIO_NOTICE; |
763 | } |
764 | |
765 | |
766 | inline bool Logger::information() const |
767 | { |
768 | return _level >= Message::PRIO_INFORMATION; |
769 | } |
770 | |
771 | |
772 | inline bool Logger::debug() const |
773 | { |
774 | return _level >= Message::PRIO_DEBUG; |
775 | } |
776 | |
777 | |
778 | inline bool Logger::trace() const |
779 | { |
780 | return _level >= Message::PRIO_TRACE; |
781 | } |
782 | |
783 | |
784 | } // namespace Poco |
785 | |
786 | |
787 | #endif // Foundation_Logger_INCLUDED |
788 | |