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 - 2023 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
243namespace Logger {
245
265
266public:
267private:
268 code callable;
269 *list<auto> args;
270
271public:
272
274
277 constructor(code func);
278
279
281
285 auto call();
286};
287
289
296class LoggerAppenderQueueThreadPool : public LoggerAppenderQueue {
297
298public:
299private:
301 ThreadPool threadPool;
303 Counter runningCounter(0);
307 hash<auto> pendingEvents;
313 Sequence lastId(0);
315 Mutex lock();
316
317public:
318
320
325private:
326 worker(string id, LoggerAppender appender, list<auto> events);
327public:
328
329
331
335 constructor(ThreadPool tp, int max_threads = -1);
336
337
338 destructor();
339
340
342 ThreadPool getThreadPool();
343
345
357 process(timeout ms = 0);
358
360 int size();
361};
362
364
367class LoggerAppenderNull : public LoggerAppender {
368
369public:
370 constructor(*string name);
371
372
373protected:
374 auto serializeImpl(LoggerEvent event);
375public:
376
377
378 processEventImpl(int type, auto params);
379};
380
382
386class LoggerAppenderStream : public LoggerAppenderWithLayout {
387
388public:
389private:
391 StreamWriter writer;
393 bool closed = False;
396
397public:
398
400
405 constructor(*string name, LoggerLayout layout, StreamWriter writer);
406
407
409 StreamWriter getStreamWriter();
410
413
415 processEventImpl(int type, auto params);
416};
417
419
423class LoggerAppenderStdOut : public LoggerAppenderWithLayout {
424
425public:
427
431 constructor(*string name, LoggerLayout layout);
432
433
435
439 processEventImpl(int type, auto params);
440};
441
443
447class LoggerAppenderStdErr : public LoggerAppenderWithLayout {
448
449public:
451
455 constructor(*string name, LoggerLayout layout);
456
457
459
463 processEventImpl(int type, auto params);
464};
465
467class AbstractLoggerAppenderFileRotate : public LoggerAppenderFile {
468
469public:
471 const EVENT_ROTATE = 10001;
474
475 constructor(*string name, LoggerLayout layout, *string encoding) : LoggerAppenderFile(name, layout, '', encoding) {}
476
477
479 abstract int getCount();};
480
482
487class LoggerAppenderFileRotate : public AbstractLoggerAppenderFileRotate, protected LoggerPattern {
488
489public:
491 const DEFAULT_ARCHIVE_PATTERN = "%p%f.%i";
492
493private:
494 int count;
495
496public:
497
499
569 constructor(*string name, LoggerLayout layout, string filename, int count = DEFAULT_ROTATION_COUNT, string archive = DEFAULT_ARCHIVE_PATTERN, *string encoding)
570 ;
571
572
574
581protected:
582 *string resolveField(auto data, string key, *string option);
583public:
584
585
587
592 processEventImpl(int type, auto params);
593
595
598 string getArchiveFileName(int idx);
599
601 int getCount();
602};
603
605
610class LoggerAppenderFileRing : public AbstractLoggerAppenderFileRotate, protected LoggerPattern {
611
612public:
614 const DEFAULT_DATE_FORMAT = "YYYYMMDDHHmmSS";
615
616private:
617 hash<auto> patternData;
618
619public:
620
622
670 constructor(*string name, LoggerLayout layout, string pattern, int count = DEFAULT_ROTATION_COUNT, *string encoding);
671
672
674
681protected:
682 *string resolveField(auto data, string key, *string option);
683public:
684
685
687
691 processEventImpl(int type, auto params);
692
694 int getCount();
695
698};
699
701
707class LoggerAppenderFileArchive : public LoggerAppenderFile, protected LoggerPattern {
708
709public:
711 const EVENT_ARCHIVE = 20;
713 const DEFAULT_DATE_FORMAT = "YYYYMMDDHHmmSS";
715 const DEFAULT_ARCHIVE_PATTERN = "%p%f.%d";
716
718
784 constructor(*string name, LoggerLayout layout, string filename, string archive = DEFAULT_ARCHIVE_PATTERN, *string encoding);
785
786
788
795protected:
796 *string resolveField(auto data, string key, *string option);
797public:
798
799
801
805 processEventImpl(int type, auto params);
806
808
814 string archive();
815
817
822};
823
825
831class LoggerFilterLevel : public LoggerFilter {
832
833public:
834private:
839
840public:
841
843
847 constructor(Qore::Logger::LoggerLevel min_value = Qore::Logger::LoggerLevel::LevelInfo, Qore::Logger::LoggerLevel max_value = Qore::Logger::LoggerLevel::LevelOff);
848
849
851
855 constructor(int min_value, int max_value = Qore::Logger::LoggerLevel::OFF);
856
857
859
863 constructor(string min_value, string max_value = 'OFF');
864
865
867
870 setMinLevel(LoggerLevel value);
871
873
876 setMinLevel(int value);
877
879
882 setMinLevel(string value);
883
885 LoggerLevel getMinLevel();
886
888
891 setMaxLevel(LoggerLevel value);
892
894
897 setMaxLevel(int value);
898
900
903 setMaxLevel(string value);
904
907
909 int eval(LoggerEvent event);
910};
911
913
917class LoggerFilterRegex : public LoggerFilter {
918
919public:
920private:
922 string regexStr;
925
926public:
927
929
933 constructor(string regex_str = '', bool regex_result = True);
934
935
937
941 setRegex(string regex_str, bool regex_result = True);
942
944 string getRegex();
945
948
950 int eval(LoggerEvent event);
951};
952
954class LoggerWrapper : public LoggerInterface {
955
956public:
957protected:
959 transient *LoggerInterface logger;
960
961public:
962
965
966
968 constructor(LoggerInterface logger);
969
970
972 setLogger(*LoggerInterface logger);
973
974
976
982 log(Qore::Logger::LoggerLevel level, string message, ...);
983
984
986
992 log(int level, string message, ...);
993
994
996
1002 log(string level, string message, ...);
1003
1004
1006
1014 logArgs(Qore::Logger::LoggerLevel level, string message, *softlist<auto> args);
1015
1016
1018
1026 logArgs(int level, string message, *softlist<auto> args);
1027
1028
1030
1038 logArgs(string level, string message, *softlist<auto> args);
1039
1040
1042
1045 logEvent(LoggerEvent event);
1046
1047
1049
1055 trace(string message, ...);
1056
1057
1059
1065 debug(string message, ...);
1066
1067
1069
1075 info(string message, ...);
1076
1077
1079
1085 warn(string message, ...);
1086
1087
1089
1095 error(string message, ...);
1096
1097
1099
1105 fatal(string message, ...);
1106
1107
1109
1120 assertLog(bool assertion, string message, ...);
1121
1122
1124
1130 traceVar(string var_name, auto value);
1131
1132
1134
1140 debugVar(string var_name, auto value);
1141
1142
1144
1147 bool isEnabledFor(LoggerLevel level);
1148
1149
1151
1154 bool isEnabledFor(int level);
1155
1156
1158
1161 bool isEnabledFor(string level);
1162
1163
1166
1167
1170
1171
1174
1175
1178
1179
1182
1183
1186
1187};
1188
1190class LoggerRoot : public Logger {
1191
1192public:
1193 // Creates the object
1197 constructor(LoggerLevel level = LoggerLevel::getLevelAll());
1198
1199
1200 // Creates the object
1204 constructor(int level);
1205
1206
1207 // Creates the object
1211 constructor(string level);
1212
1213
1215
1221 setLevel(*LoggerLevel value);
1222
1224
1228};
1229
1231
1233class StdoutAppender : public LoggerAppenderWithLayout {
1234
1235public:
1236 constructor() ;
1237
1238
1239 processEventImpl(int type, auto params);
1240
1241};
1242};
Abstract class for file appenders with rotation support.
Definition: Logger.qm.dox.h:467
const EVENT_ROTATE
rotate event
Definition: Logger.qm.dox.h:471
const DEFAULT_ROTATION_COUNT
default value for rotation chain
Definition: Logger.qm.dox.h:473
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:707
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:713
string archive()
Posts an archive event.
const EVENT_ARCHIVE
archive event
Definition: Logger.qm.dox.h:711
const DEFAULT_ARCHIVE_PATTERN
default archive pattern
Definition: Logger.qm.dox.h:715
*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:610
int getCount()
Returns number of files in ring.
const DEFAULT_DATE_FORMAT
default date format
Definition: Logger.qm.dox.h:614
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:487
string getArchiveFileName(int idx)
Returns the archive filename.
const DEFAULT_ARCHIVE_PATTERN
default archive pattern
Definition: Logger.qm.dox.h:491
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:367
Handles the processing for asynchronous appender events in multiple threads.
Definition: Logger.qm.dox.h:296
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:307
Mutex lock()
to protect process()
ThreadPool threadPool
worker thread pool
Definition: Logger.qm.dox.h:301
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:309
int maxThreads
max.number of worker threads
Definition: Logger.qm.dox.h:305
Implements appender writing to a stderr file.
Definition: Logger.qm.dox.h:447
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:423
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:386
bool closed
closed flag
Definition: Logger.qm.dox.h:393
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:395
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:391
Implements callable parameter which is evaluated in run-time when event is rendered.
Definition: Logger.qm.dox.h:264
constructor(code func)
Creates object.
auto call()
Call function with arguments provided.
Implements the filter according event LoggerLevel.
Definition: Logger.qm.dox.h:831
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:836
Qore::Logger::LoggerLevel maxLevel
max.level
Definition: Logger.qm.dox.h:838
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:917
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:922
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:924
Implements the root class for loggers; does not allow a parent logger to be set.
Definition: Logger.qm.dox.h:1190
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:954
constructor()
Creates the object with no logger.
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.
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.
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:959
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.
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.
Appender for logging to the console.
Definition: Logger.qm.dox.h:1233
The Logger namespace contains all the definitions in the Logger module.
Definition: Logger.qm.dox.h:243