PLog Class Reference

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

Definition at line 72 of file PLog.h.

#include <PLog.h>

Member Enumeration Documentation

◆ ELogLevel

All the available log levels.

Enumerator
E_LEVEL_TRACE 

A trace severity message.

E_LEVEL_DEBUG 

A debug severity message.

E_LEVEL_INFO 

A informational severity message.

E_LEVEL_WARNING 

A warning severity message.

E_LEVEL_ERROR 

An error severity message.

E_LEVEL_FATAL 

A fatal severity message.

Definition at line 81 of file PLog.h.

◆ ERegExpPattern

All the available way to interpret regular expression patterns.

Enumerator
E_REGEXP_PERL 

A rich Perl-like pattern matching syntax.

E_REGEXP_WILDCARD 

Simple pattern matching syntax similar to that used by shells.

Definition at line 94 of file PLog.h.

Member Function Documentation

◆ Close()

static PResult PLog::Close ( const PString loggerName)
static

Closes the specified logger (thread-safe).

Returns PResult::C_OK if success, another result otherwise (e.g. source does not exist).

◆ CloseConsole()

static PResult PLog::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 void PLog::DisableConsoleLogger ( )
static

Disables the console logger.

◆ DisableConsoleLoggerOnDebug()

static void PLog::DisableConsoleLoggerOnDebug ( )
static

Call this method before PapillonSDK::Initialise(...) to disable console logger on debug.

◆ EnableConsoleLogger()

static void PLog::EnableConsoleLogger ( )
static

Enables the console logger.

◆ GetConsoleLevel()

static ELogLevel PLog::GetConsoleLevel ( )
static

Gets the log level of the specified console logger (thread-safe).

Returns E_LEVEL_INFO if the logger does not exist.

◆ GetLevel()

static ELogLevel PLog::GetLevel ( const PString loggerName)
static

Gets the log level of the specified logger (thread-safe).

Returns E_LEVEL_INFO if the logger does not exist.

◆ GetPrefix()

static const PString& PLog::GetPrefix ( )
static

Gets the message prefix used before each log message.

◆ Log()

static PResult PLog::Log ( ELogLevel  level,
const PString message,
papillon::int32  lineNumber = 0,
const PString filename = PString::Empty() 
)
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 ELogLevel PLog::LogLevelFromString ( const char *  stringLevel)
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 PResult PLog::OpenCallbackLogger ( const PString loggerName,
PCallback_Logger  callback,
ELogLevel  level = E_LEVEL_INFO 
)
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 PResult PLog::OpenConsoleLogger ( ELogLevel  level = E_LEVEL_INFO)
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 PResult PLog::OpenFileLogger ( const PString loggerName,
const PString destinationFilename,
ELogLevel  level = E_LEVEL_INFO,
int  maximumNumberOfLogs = -1,
int  maximumNumberOfLogFiles = 30 
)
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()

static PResult PLog::SetConsoleFormat ( const PString format)
static

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()

static PResult PLog::SetConsoleLevel ( ELogLevel  level)
static

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()

static PResult PLog::SetFormat ( const PString loggerName,
const PString format 
)
static

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()

static PResult PLog::SetLevel ( const PString loggerName,
ELogLevel  level 
)
static

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 void PLog::SetPrefix ( const PString prefix)
static

Sets the message prefix to use before each log message.

◆ SetRegExpFilter()

static PResult PLog::SetRegExpFilter ( const PString loggerName,
const PString regExpPattern,
ERegExpPattern  syntax = E_REGEXP_WILDCARD 
)
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.