Buteo Synchronization Framework: Buteo::Logger Class Reference

Buteo Synchronization Framework

Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
Buteo::Logger Class Reference

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.

## Detailed Description

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.

## Member Function Documentation

## ◆ createInstance()

void Logger::createInstance | ( | const QString & | aLogFileName = `""`,
|  | bool | aUseStdOut = `false`,
|  | int | aIndentSize = `DEFAULT_INDENT_SIZE`
| ) |  |
| 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.

Parameters

  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.

## ◆ disable()

void Logger::disable | ( | const QBitArray & | aLevels = `QBitArray(NUM_LEVELS, true)` | ) |

Disables given log levels.

Parameters

  aLevels | Log levels to disable. Default disables all levels.

## ◆ enable()

void Logger::enable | ( | const QBitArray & | aLevels = `QBitArray(NUM_LEVELS, true)` | ) |

Enables given log levels.

Parameters

  aLevels | Log levels to enable. Default enables all levels.

## ◆ getLogLevelArray()

QBitArray Logger::getLogLevelArray | ( |  | ) |

Gets logging level BitArray.

Use this API to count the levels the BitArray has been set to true

## ◆ instance()

Logger * Logger::instance | ( |  | ) |
| static

Returns the logger instance.

If the instance is not yet created, creates it with default parameters.

Returns
  The instance.

## ◆ setLogLevel()

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.

Parameters

  aLevel | Logging level.

## ◆ write()

void Logger::write | ( | int | aLevel,
|  | const char * | aMsg
| ) |  |

Writes a message to the log.

Parameters

  aLevel | Message level.
  aMsg | Message.

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

- Logger.h
- Logger.cpp