Logger class provides methods for logging messages. More...

Public Types

enum  LogLevel { LogAll = 0, Warning, Quiet, Superquiet }
 

Static Public Member Functions

static void enableStdOut (bool enabled)
 Enable/Disable the printing of log messages on the standard out. More...
 
static void error (QString msg)
 Log an error message. More...
 
static void info (QString msg)
 Log an informative message. More...
 
static QString logLevelToString (LogLevel level)
 Returns the string representation of the given log level. More...
 
static void setLogFilename (QString logfile)
 Set the filename where to log messages. More...
 
static void setLogLevel (LogLevel level)
 Sets the current log level (which influences what is logged and what isn't). More...
 
static void setQTextEdit (QTextEdit *textedit)
 Set a QTextEdit dedicated for showing log messages. More...
 
static LogLevel stringToLogLevel (QString level)
 Returns the log level given its string representation. More...
 
static void warning (QString msg)
 Log a warning message. More...
 

Detailed Description

Logger class provides methods for logging messages.

Logger has only static method. There is no need to instantiate it, just use the static method appropriate to log your message.

The Logger automatically add a timestamp and the information about the level of message. You just need to provide the message to log.

Be careful which methods you call from which thread: not every method in this class is thread safe (see method description). When you call a method that is not thread-safe you must be sure no other thread is accessing the logger

Note
It does not provides methods for formatting a message, but it uses QString. Hence, use the QString methods for formatting the message
Do not use the logger after returning from the main method (during static data cleanup)

Definition at line 52 of file logger.h.

Member Function Documentation

void enableStdOut ( bool  enabled)
static

Enable/Disable the printing of log messages on the standard out.

This method is NOT thread-safe

Parameters
enabledif true Logger will print on standard out the messages, otherwise no

Definition at line 284 of file logger.cpp.

void error ( QString  msg)
static

Log an error message.

This method is thread-safe

Parameters
msgthe message to log (timestamp & info level info are prepend to msg)

Definition at line 269 of file logger.cpp.

void info ( QString  msg)
static

Log an informative message.

This method is thread-safe

Parameters
msgthe message to log (timestamp & info level info are prepend to msg)

Definition at line 259 of file logger.cpp.

QString logLevelToString ( Logger::LogLevel  level)
static

Returns the string representation of the given log level.

This method is thread-safe

Parameters
levelthe log level
Returns
the string representation of the given log level

Definition at line 293 of file logger.cpp.

References Logger::LogAll, Logger::Quiet, Logger::Superquiet, and Logger::Warning.

void setLogFilename ( QString  logfile)
static

Set the filename where to log messages.

This method is NOT thread-safe

Parameters
logfileis the filename (full path or relative to the working directory) where to store log messages
Note
the filename is always open in append mode

Definition at line 274 of file logger.cpp.

void setLogLevel ( LogLevel  level)
static

Sets the current log level (which influences what is logged and what isn't).

This method is NOT thread-safe

Parameters
levelthe new log level

Definition at line 289 of file logger.cpp.

void setQTextEdit ( QTextEdit *  textedit)
static

Set a QTextEdit dedicated for showing log messages.

This method is NOT thread-safe

Definition at line 279 of file logger.cpp.

Logger::LogLevel stringToLogLevel ( QString  level)
static

Returns the log level given its string representation.

This method is thread-safe

Parameters
levelthe string representation of a log level (this is case insensitive)
Returns
the log level corresponding to the given string (or Default if the string is invalid)

Definition at line 316 of file logger.cpp.

References Logger::LogAll, Logger::Quiet, Logger::Superquiet, and Logger::Warning.

void warning ( QString  msg)
static

Log a warning message.

This method is thread-safe

Parameters
msgthe message to log (timestamp & info level info are prepend to msg)

Definition at line 264 of file logger.cpp.


The documentation for this class was generated from the following files: