Detailed Description
The PLog class represents the log system (singleton) used by Papillon; thread-safe.
You cannot create instances of PLog.
PLog supports several loggers at the same time.
Features of the log system are the following:
- Log messages are UTF-8 encoded.
- Several loggers can be opened at the same time (console, file, callback), see OpenConsoleLogger(), OpenFileLogger(), etc. to open loggers.
- Log messages are sent to all opened loggers.
- Loggers are thread-safe: you can log messages from different threads.
- Each logger has a name.
- Each logger can have its own level to filter messages (all log messages with severity equal or higher than the specified level will be logged).
- Each logger can (optionally) use a reg-exp filter.
- Each logger can have a different formatter used to format log messages.
Log message formatting: Use a PString object (a string) to specify the format. Default format is "date tid (sev): msg". To build a format, the following tags are available:
- date = timestamp
- tid = thread id
- line = line number
- file = filename
- sev = severity
- msg = message
#include <PLog.h>
Member Enumeration Documentation
◆ ELogLevel
enum PLog::ELogLevel |
◆ ERegExpPattern
enum PLog::ERegExpPattern |
Member Function Documentation
◆ Close()
Closes the specified logger (thread-safe).
Returns PResult::C_OK if success, another result otherwise (e.g. source does not exist).
◆ CloseConsole()
|
static |
Closes the console logger (thread-safe).
Returns PResult::C_OK if success, another result otherwise (e.g. source does not exist).
◆ DisableConsoleLogger()
|
static |
Disables the console logger.
◆ DisableConsoleLoggerOnDebug()
|
static |
Call this method before PapillonSDK::Initialise(...) to disable console logger on debug.
◆ EnableConsoleLogger()
|
static |
Enables the console logger.
◆ GetConsoleLevel()
|
static |
Gets the log level of the specified console logger (thread-safe).
Returns E_LEVEL_INFO if the logger does not exist.
◆ GetLevel()
Gets the log level of the specified logger (thread-safe).
Returns E_LEVEL_INFO if the logger does not exist.
◆ GetPrefix()
|
static |
Gets the message prefix used before each log message.
◆ Log()
|
static |
Writes a log message with the specified severity (thread-safe).
You should use LogM() macro instead of Log() function. LogM() macro can retrieve line number and filename.
Returns PResult::C_OK if success, another result otherwise.
◆ LogLevelFromString()
|
static |
Converts the specified string to ELogLevel enum.
Accepted strings are the followings: "trace", "debug", "info", "warning", "error", "fatal". Returns E_LEVEL_DEBUG if stringLevel is not recognized.
◆ OpenCallbackLogger()
|
static |
Opens a new logger to callback (thread-safe).
If a callback logger with the same name already exists this new call is ignored. Log messages will be send to the specified callback. Returns PResult::C_OK if success, another result otherwise.
◆ OpenConsoleLogger()
|
static |
Opens a logger to console (thread-safe); do nothing if already opened.
Log messages will be send to std::cout. Returns PResult::C_OK if success, another result otherwise.
◆ OpenFileLogger()
|
static |
Opens a new logger to file (thread-safe).
If a file logger with the same name already exists this new call is ignored. Log messages will be send to the specified text file. The parameter maximumNumberOfLogs allows to set the maximum number of lines in the log file (no limit by default). When the limit is reached, the current log file is archived with the current date and a new log file is created. The log file is also archived every day. By default, the system keeps up to 30 log files. Returns PResult::C_OK if success, another result otherwise.
◆ SetConsoleFormat()
Sets or changes the log format of the console logger (thread-safe).
Format is a string containing 1 or several of the following tags:
- date = timestamp
- tid = thread id
- line = line number
- file = filename
- sev = severity
- msg = message
Example of format: "ts - [tid] - (sev): msg"
Returns PResult::C_OK if success, another result otherwise.
◆ SetConsoleLevel()
Sets or changes the log level of the console logger (thread-safe).
All log messages with severity strictly smaller than the specified level will be skipped. Returns PResult::C_OK if success, another result otherwise.
◆ SetFormat()
Sets or changes the log format for the specified logger (thread-safe).
Format is a string containing 1 or several of the following tags:
- date = timestamp
- tid = thread id
- line = line number
- file = filename
- sev = severity
- msg = message
Example of format: "ts - [tid] - (sev): msg"
Returns PResult::C_OK if success, another result otherwise.
◆ SetLevel()
Sets or changes the log level of the specified logger (thread-safe).
All log messages with severity strictly smaller than the specified level will be skipped. Returns PResult::C_OK if success, another result otherwise.
◆ SetPrefix()
|
static |
Sets the message prefix to use before each log message.
◆ SetRegExpFilter()
|
static |
Sets the regular expression used to filter log messages (thread-safe).
By default, loggers do not filter log messages.
Returns PResult::C_OK if success, another result otherwise.