ButeoSynchronizationFramework
|
A logger singleton class. More...
#include <Logger.h>
Public Member Functions | |
~Logger () | |
Destructor. | |
void | enable (const QBitArray &aLevels=QBitArray(NUM_LEVELS, true)) |
Enables given log levels. More... | |
void | disable (const QBitArray &aLevels=QBitArray(NUM_LEVELS, true)) |
Disables given log levels. More... | |
void | push () |
Adds one indent level. | |
void | pop () |
Removes one indent level. | |
void | write (int aLevel, const char *aMsg) |
Writes a message to the log. More... | |
bool | setLogLevel (int aLevel) |
Sets logging level. More... | |
QBitArray | getLogLevelArray () |
Gets logging level BitArray. More... | |
int | getLogLevel () const |
Gets the logging level as a single number. | |
bool | enabled () |
Static Public Member Functions | |
static Logger * | instance () |
Returns the logger instance. More... | |
static void | createInstance (const QString &aLogFileName="", bool aUseStdOut=false, int aIndentSize=DEFAULT_INDENT_SIZE) |
Creates a logger instance. More... | |
static void | deleteInstance () |
Deletes the logger instance. Closes the log file in a controlled way. | |
Static Public Attributes | |
static const int | NUM_LEVELS = 4 |
static const int | DEFAULT_INDENT_SIZE = 4 |
Default indent size. | |
A logger singleton class.
Using the logger is thread safe, but creating the instance is not. Make sure that the instance is created before any threads that use the logger are started. This can be done by calling createInstance explicitly, or by simply logging some message, which will automatically create the logger instance with default parameters.
|
static |
Creates a logger instance.
If an instance already exists, deletes the old instance first. This function should be called in the beginning of the program before any threads using the logger are created, because creating the log instance is not thread safe.
aLogFileName | Name of the file where log messages are written. If this is empty, messages are not written to a file. |
aUseStdOut | Should messages be written to standard output. |
aIndentSize | Number of spaces that each indent level inserts. |
void Logger::disable | ( | const QBitArray & | aLevels = QBitArray(NUM_LEVELS, true) | ) |
Disables given log levels.
aLevels | Log levels to disable. Default disables all levels. |
void Logger::enable | ( | const QBitArray & | aLevels = QBitArray(NUM_LEVELS, true) | ) |
Enables given log levels.
aLevels | Log levels to enable. Default enables all levels. |
QBitArray Logger::getLogLevelArray | ( | ) |
Gets logging level BitArray.
Use this API to count the levels the BitArray has been set to true
|
static |
Returns the logger instance.
If the instance is not yet created, creates it with default parameters.
bool Logger::setLogLevel | ( | int | aLevel | ) |
Sets logging level.
Messages with the given level and levels more severe than it will be enabled. Qt built-in log levels will also be enabled.
aLevel | Logging level. |
void Logger::write | ( | int | aLevel, |
const char * | aMsg | ||
) |
Writes a message to the log.
aLevel | Message level. |
aMsg | Message. |