Qore Logger Module Reference 1.0
Loading...
Searching...
No Matches
Logger.qm.dox.h
1// -*- mode: c++; indent-tabs-mode: nil -*-
3
4/* Logger.qm Copyright 2018 - 2024 Qore Technologies, s.r.o.
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23*/
24
25// minimum required Qore version
26
27
28
29// import native code for logger
30
31
244namespace Logger {
246
266
267public:
268private:
269 code callable;
270 *list<auto> args;
271
272public:
273
275
278 constructor(code func, ...);
279
280
282
286 auto call();
287};
288
290
297class LoggerAppenderQueueThreadPool : public LoggerAppenderQueue {
298
299public:
300private:
302 ThreadPool threadPool;
304 Counter runningCounter(0);
308 hash<auto> pendingEvents;
314 Sequence lastId(0);
316 Mutex lock();
317
318public:
319
321
326private:
327 worker(string id, LoggerAppender appender, list<auto> events);
328public:
329
330
332
336 constructor(ThreadPool tp, int max_threads = -1);
337
338
339 destructor();
340
341
343 ThreadPool getThreadPool();
344
346
358 process(timeout ms = 0);
359
361 int size();
362};
363
365
368class LoggerAppenderNull : public LoggerAppender {
369
370public:
371 constructor(*string name);
372
373
374protected:
375 auto serializeImpl(LoggerEvent event);
376public:
377
378
379 processEventImpl(int type, auto params);
380};
381
383
387class LoggerAppenderStream : public LoggerAppenderWithLayout {
388
389public:
390private:
392 StreamWriter writer;
394 bool closed = False;
397
398public:
399
401
406 constructor(*string name, LoggerLayout layout, StreamWriter writer);
407
408
410 StreamWriter getStreamWriter();
411
414
416 processEventImpl(int type, auto params);
417};
418
420
424class LoggerAppenderStdOut : public LoggerAppenderWithLayout {
425
426public:
428
432 constructor(*string name, LoggerLayout layout);
433
434
436
440 processEventImpl(int type, auto params);
441};
442
444
448class LoggerAppenderStdErr : public LoggerAppenderWithLayout {
449
450public:
452
456 constructor(*string name, LoggerLayout layout);
457
458
460
464 processEventImpl(int type, auto params);
465};
466
468class AbstractLoggerAppenderFileRotate : public LoggerAppenderFile {
469
470public:
472 const EVENT_ROTATE = 10001;
474 const EVENT_REOPEN = 10002;
477
478 constructor(*string name, LoggerLayout layout, *string encoding) : LoggerAppenderFile(name, layout, '', encoding) {}
479
480
482
488
490 abstract int getCount();};
491
493
498class LoggerAppenderFileRotate : public AbstractLoggerAppenderFileRotate, protected LoggerPattern {
499
500public:
502 const DEFAULT_ARCHIVE_PATTERN = "%p%f.%i";
503
504private:
505 int count;
506
507public:
508
510
580 constructor(*string name, LoggerLayout layout, string filename, int count = DEFAULT_ROTATION_COUNT, string archive = DEFAULT_ARCHIVE_PATTERN, *string encoding)
581 ;
582
583
585
592protected:
593 *string resolveField(auto data, string key, *string option);
594public:
595
596
598
603 processEventImpl(int type, auto params);
604
606
609 string getArchiveFileName(int idx);
610
612 int getCount();
613};
614
616
621class LoggerAppenderFileRing : public AbstractLoggerAppenderFileRotate, protected LoggerPattern {
622
623public:
625 const DEFAULT_DATE_FORMAT = "YYYYMMDDHHmmSS";
626
627private:
628 hash<auto> patternData;
629
630public:
631
633
681 constructor(*string name, LoggerLayout layout, string pattern, int count = DEFAULT_ROTATION_COUNT, *string encoding);
682
683
685
692protected:
693 *string resolveField(auto data, string key, *string option);
694public:
695
696
698
702 processEventImpl(int type, auto params);
703
705 int getCount();
706
709};
710
712
718class LoggerAppenderFileArchive : public LoggerAppenderFile, protected LoggerPattern {
719
720public:
722 const EVENT_ARCHIVE = 20;
724 const DEFAULT_DATE_FORMAT = "YYYYMMDDHHmmSS";
726 const DEFAULT_ARCHIVE_PATTERN = "%p%f.%d";
727
729
795 constructor(*string name, LoggerLayout layout, string filename, string archive = DEFAULT_ARCHIVE_PATTERN, *string encoding);
796
797
799
806protected:
807 *string resolveField(auto data, string key, *string option);
808public:
809
810
812
816 processEventImpl(int type, auto params);
817
819
825 string archive();
826
828
833};
834
836
842class LoggerFilterLevel : public LoggerFilter {
843
844public:
845private:
850
851public:
852
854
858 constructor(Qore::Logger::LoggerLevel min_value = Qore::Logger::LoggerLevel::LevelInfo, Qore::Logger::LoggerLevel max_value = Qore::Logger::LoggerLevel::LevelOff);
859
860
862
866 constructor(int min_value, int max_value = Qore::Logger::LoggerLevel::OFF);
867
868
870
874 constructor(string min_value, string max_value = 'OFF');
875
876
878
881 setMinLevel(LoggerLevel value);
882
884
887 setMinLevel(int value);
888
890
893 setMinLevel(string value);
894
896 LoggerLevel getMinLevel();
897
899
902 setMaxLevel(LoggerLevel value);
903
905
908 setMaxLevel(int value);
909
911
914 setMaxLevel(string value);
915
918
920 int eval(LoggerEvent event);
921};
922
924
928class LoggerFilterRegex : public LoggerFilter {
929
930public:
931private:
933 string regexStr;
936
937public:
938
940
944 constructor(string regex_str = '', bool regex_result = True);
945
946
948
952 setRegex(string regex_str, bool regex_result = True);
953
955 string getRegex();
956
959
961 int eval(LoggerEvent event);
962};
963
965class LoggerWrapper : public LoggerInterface {
966
967public:
968protected:
970 transient *LoggerInterface logger;
971
972public:
973
976
977
979 constructor(LoggerInterface logger);
980
981
983 bool isLogger(LoggerInterface logger);
984
985
987 setLogger(*LoggerInterface logger);
988
989
991
997 log(Qore::Logger::LoggerLevel level, string message, ...);
998
999
1001
1007 log(int level, string message, ...);
1008
1009
1011
1017 log(string level, string message, ...);
1018
1019
1021
1029 logArgs(Qore::Logger::LoggerLevel level, string message, *softlist<auto> args);
1030
1031
1033
1041 logArgs(int level, string message, *softlist<auto> args);
1042
1043
1045
1053 logArgs(string level, string message, *softlist<auto> args);
1054
1055
1057
1060 logEvent(LoggerEvent event);
1061
1062
1064
1070 trace(string message, ...);
1071
1072
1074
1080 debug(string message, ...);
1081
1082
1084
1090 info(string message, ...);
1091
1092
1094
1100 warn(string message, ...);
1101
1102
1104
1110 error(string message, ...);
1111
1112
1114
1120 fatal(string message, ...);
1121
1122
1124
1135 assertLog(bool assertion, string message, ...);
1136
1137
1139
1145 traceVar(string var_name, auto value);
1146
1147
1149
1155 debugVar(string var_name, auto value);
1156
1157
1159
1162 bool isEnabledFor(LoggerLevel level);
1163
1164
1166
1169 bool isEnabledFor(int level);
1170
1171
1173
1176 bool isEnabledFor(string level);
1177
1178
1181
1182
1185
1186
1189
1190
1193
1194
1197
1198
1201
1202
1204
1207 setLevel(*LoggerLevel level);
1208
1209
1211
1214 setLevel(string level);
1215
1216
1218
1221 setLevel(int level);
1222
1223
1225
1228 *LoggerLevel decLevel();
1229
1230
1232
1235 *LoggerLevel incLevel();
1236
1237
1239
1243 *LoggerLevel getLevel(bool effective = True);
1244
1245
1247protected:
1248 *LoggerInterface getLogger();
1249public:
1250
1251};
1252
1254class LoggerRoot : public Logger {
1255
1256public:
1257 // Creates the object
1261 constructor(LoggerLevel level = LoggerLevel::getLevelAll());
1262
1263
1264 // Creates the object
1268 constructor(int level);
1269
1270
1271 // Creates the object
1275 constructor(string level);
1276
1277
1279
1285 setLevel(*LoggerLevel value);
1286
1288
1292};
1293
1295
1297class StdoutAppender : public LoggerAppenderWithLayout {
1298
1299public:
1300 constructor() ;
1301
1302
1303 processEventImpl(int type, auto params);
1304
1305};
1306};
Abstract class for file appenders with rotation support.
Definition Logger.qm.dox.h:468
const EVENT_REOPEN
reopen event
Definition Logger.qm.dox.h:474
const EVENT_ROTATE
rotate event
Definition Logger.qm.dox.h:472
const DEFAULT_ROTATION_COUNT
default value for rotation chain
Definition Logger.qm.dox.h:476
abstract int getCount()
Abstract method to get count of rotation objects.
Implements appender writing to a file with archive support.
Definition Logger.qm.dox.h:718
constructor(*string name, LoggerLayout layout, string filename, string archive=DEFAULT_ARCHIVE_PATTERN, *string encoding)
Creates the object.
processEventImpl(int type, auto params)
Implements archiving, handles the archive event directly, passes all other events to the subclass for...
const DEFAULT_DATE_FORMAT
default date format
Definition Logger.qm.dox.h:724
string archive()
Posts an archive event.
const EVENT_ARCHIVE
archive event
Definition Logger.qm.dox.h:722
const DEFAULT_ARCHIVE_PATTERN
default archive pattern
Definition Logger.qm.dox.h:726
*string resolveField(auto data, string key, *string option)
Returns a string for a format field for a pattern-based filename or archive file name.
string getArchiveFileName()
Returns the archive filename.
Implemants appender writing to a file with file circular rotation support.
Definition Logger.qm.dox.h:621
int getCount()
Returns number of files in ring.
const DEFAULT_DATE_FORMAT
default date format
Definition Logger.qm.dox.h:625
constructor(*string name, LoggerLayout layout, string pattern, int count=DEFAULT_ROTATION_COUNT, *string encoding)
Creates the object.
processEventImpl(int type, auto params)
Implements filename rotation; handles the open and rotate events directly; passes all other events to...
*string resolveField(auto data, string key, *string option)
Returns a string for a format field for a pattern-based filename.
int getCurrentIndex()
Returns current ring index being used for logging.
Implements appender writing to a file with file rotation support.
Definition Logger.qm.dox.h:498
string getArchiveFileName(int idx)
Returns the archive filename.
const DEFAULT_ARCHIVE_PATTERN
default archive pattern
Definition Logger.qm.dox.h:502
processEventImpl(int type, auto params)
Implements filename rotation; handles the open and rotate events directly.
*string resolveField(auto data, string key, *string option)
Returns a string for a format field for a pattern-based filename.
int getCount()
Returns max.number of files in chain.
constructor(*string name, LoggerLayout layout, string filename, int count=DEFAULT_ROTATION_COUNT, string archive=DEFAULT_ARCHIVE_PATTERN, *string encoding)
Creates the object.
Implements appender which does nothing.
Definition Logger.qm.dox.h:368
Handles the processing for asynchronous appender events in multiple threads.
Definition Logger.qm.dox.h:297
worker(string id, LoggerAppender appender, list< auto > events)
Implements worker thread code.
constructor(ThreadPool tp, int max_threads=-1)
Creates the object.
Counter runningCounter(0)
number of running worker threads
process(timeout ms=0)
Processes queue events.
Sequence lastId(0)
internal unique counter
hash< auto > pendingEvents
events removed from queue but not passed to worker thread
Definition Logger.qm.dox.h:308
Mutex lock()
to protect process()
ThreadPool threadPool
worker thread pool
Definition Logger.qm.dox.h:302
Queue finishedEvents()
queue of processed events in worker threads
ThreadPool getThreadPool()
Returns the assigned ThreadPool.
int size()
Gets number of pending events.
hash< auto > processingEvents
events paseed to worker thread
Definition Logger.qm.dox.h:310
int maxThreads
max.number of worker threads
Definition Logger.qm.dox.h:306
Implements appender writing to a stderr file.
Definition Logger.qm.dox.h:448
constructor(*string name, LoggerLayout layout)
Creates the object.
processEventImpl(int type, auto params)
Processes log events with the file and ignores all other events including open, close.
Implements appender writing to a stdout file.
Definition Logger.qm.dox.h:424
processEventImpl(int type, auto params)
Processes log events with the file and ignores all other events including open, close.
constructor(*string name, LoggerLayout layout)
Creates the object.
implements appender writing to an output stream via StreamWriter
Definition Logger.qm.dox.h:387
bool closed
closed flag
Definition Logger.qm.dox.h:394
bool hasAssignThread()
Returns True if assigning a thread for a stream.
constructor(*string name, LoggerLayout layout, StreamWriter writer)
Creates the object.
StreamWriter getStreamWriter()
Returns the stream writer object.
bool assignThread
assign thread for stream
Definition Logger.qm.dox.h:396
processEventImpl(int type, auto params)
Processes open, log, and close events with the output stream; all other events are ignored.
StreamWriter writer
stream writer
Definition Logger.qm.dox.h:392
Implements callable parameter which is evaluated in run-time when event is rendered.
Definition Logger.qm.dox.h:265
constructor(code func,...)
Creates object.
auto call()
Call function with arguments provided.
Implements the filter according event LoggerLevel.
Definition Logger.qm.dox.h:842
int eval(LoggerEvent event)
Implements filtering by level.
Qore::Logger::LoggerLevel getMaxLevel()
Returns the maximum logging level.
setMinLevel(LoggerLevel value)
Sets the minimum logging level.
setMaxLevel(string value)
Sets the maximum logging level.
constructor(Qore::Logger::LoggerLevel min_value=Qore::Logger::LoggerLevel::LevelInfo, Qore::Logger::LoggerLevel max_value=Qore::Logger::LoggerLevel::LevelOff)
Creates the object.
setMinLevel(int value)
Sets the minimum logging level.
Qore::Logger::LoggerLevel minLevel
min.level
Definition Logger.qm.dox.h:847
Qore::Logger::LoggerLevel maxLevel
max.level
Definition Logger.qm.dox.h:849
constructor(string min_value, string max_value='OFF')
Creates the object.
setMaxLevel(LoggerLevel value)
Sets the maximum logging level.
constructor(int min_value, int max_value=Qore::Logger::LoggerLevel::OFF)
Creates the object.
setMinLevel(string value)
Sets the minimum logging level.
setMaxLevel(int value)
Sets the maximum logging level.
LoggerLevel getMinLevel()
Returns the minimum logging level.
Implements filtering according to a regular expression on the event message.
Definition Logger.qm.dox.h:928
int eval(LoggerEvent event)
Evaluates the regex and compares with the expected result.
constructor(string regex_str='', bool regex_result=True)
Creates the object.
string regexStr
regular string
Definition Logger.qm.dox.h:933
setRegex(string regex_str, bool regex_result=True)
Sets the regular expression and the expected result for the filter.
string getRegex()
Returns the current regex.
bool getRegexResult()
Returns the expected result.
bool regexResult
expected result
Definition Logger.qm.dox.h:935
Implements the root class for loggers; does not allow a parent logger to be set.
Definition Logger.qm.dox.h:1254
setParent(*Logger value)
Overrides value setter as the root logger cannot have a parent; this method always throws an exceptio...
constructor(string level)
constructor(int level)
setLevel(*LoggerLevel value)
Overrides the level setter to prevent setting the root logger's level to NOTHING (an exception is thr...
constructor(LoggerLevel level=LoggerLevel::getLevelAll())
Class handling a LoggerInterface object as a member and providing atomic logging through it.
Definition Logger.qm.dox.h:965
constructor()
Creates the object with no logger.
*LoggerLevel getLevel(bool effective=True)
Returns the logging level.
*LoggerLevel decLevel()
Decrement logger level.
warn(string message,...)
Logs a message object with the WARN level.
log(int level, string message,...)
Logs a message using the provided logging level if a logger is set.
log(Qore::Logger::LoggerLevel level, string message,...)
Logs a message using the provided logging level if a logger is set.
debug(string message,...)
Logs a message object with the DEBUG level.
*LoggerInterface getLogger()
Returns the logger interface for logging.
fatal(string message,...)
Logs a message object with the FATAL level.
traceVar(string var_name, auto value)
Logs the variable name and value using TRACE level.
bool isDebugEnabled()
Checks whether this Logger is enabled for the DEBUG Level.
bool isEnabledFor(int level)
Checks whether this Logger is enabled for a given Level passed as parameter.
setLevel(int level)
Sets the logging level.
debugVar(string var_name, auto value)
Logs the variable name and value using DEBUG level.
logArgs(string level, string message, *softlist< auto > args)
Logs a message using the provided logging level and a single argument for any format string arguments...
logArgs(Qore::Logger::LoggerLevel level, string message, *softlist< auto > args)
Logs a message using the provided logging level and a single argument for any format string arguments...
log(string level, string message,...)
Logs a message using the provided logging level if a logger is set.
bool isErrorEnabled()
Checks whether this Logger is enabled for the ERROR Level.
bool isEnabledFor(LoggerLevel level)
Checks whether this Logger is enabled for a given Level passed as parameter.
logArgs(int level, string message, *softlist< auto > args)
Logs a message using the provided logging level and a single argument for any format string arguments...
trace(string message,...)
Logs a message object with the TRACE level.
error(string message,...)
Logs a message object with the ERROR level.
setLogger(*LoggerInterface logger)
Accepts a LoggerInterface object for logging (or clears it)
transient *LoggerInterface logger
The logger interface.
Definition Logger.qm.dox.h:970
constructor(LoggerInterface logger)
Creates the object with a logger.
bool isFatalEnabled()
Checks whether this Logger is enabled for the FATAL Level.
bool isInfoEnabled()
Checks whether this Logger is enabled for the INFO Level.
setLevel(string level)
Sets the logging level.
setLevel(*LoggerLevel level)
Sets the logging level.
bool isEnabledFor(string level)
Checks whether this Logger is enabled for a given Level passed as parameter.
bool isTraceEnabled()
Checks whether this Logger is enabled for the TRACE Level.
info(string message,...)
Logs a message object with the INFO level.
logEvent(LoggerEvent event)
Logs an already prepared logging event object.
assertLog(bool assertion, string message,...)
Performs logging of assertions.
bool isWarnEnabled()
Checks whether this Logger is enabled for the WARN Level.
*LoggerLevel incLevel()
Increment logger level.
bool isLogger(LoggerInterface logger)
Returns True if the passed logger is the logger used to log, False if not.
Appender for logging to the console.
Definition Logger.qm.dox.h:1297
The Logger namespace contains all the definitions in the Logger module.
Definition Logger.qm.dox.h:244