logger
Classes | Enumerations | Functions
logger Namespace Reference

Logger namespace. Contains all available functions and classes. More...

Classes

class  Line
 Allows piping content in order to build a log message. Once the object is destroyed, the piped content will be logged to the appropriate outputs. More...
 

Enumerations

enum  Level {
  Verbose, Debug, Info, Warning,
  Error, Off
}
 Levels for filtering messages based on importance. More...
 

Functions

bool enabled ()
 Checks if the logger is enabled. More...
 
Level consoleLevel ()
 Gets the minimum Level for console output. More...
 
Level fileLevel ()
 Gets the minimum Level for file output. More...
 
std::string logFile ()
 Gets the output file for file logging. More...
 
void enable (const Level &consoleLevel=Info, const Level &fileLevel=Off, const std::string &logFileFormat="log/%Y-%m-%d-%H-%M-%S.txt")
 Enables the logger with the given minimum Levels. Call again to change these settings. This results in a new log file being generated, if file logging is enabled. More...
 
void disable ()
 Disables the logger.
 
int contextLength ()
 Gets the context lenght. More...
 
void setContextLength (const int &contextLength)
 Sets the context lenght. More...
 
bool printTime ()
 Checks whether the current time is included in output. More...
 
void setPrintTime (const bool &printTime)
 Sets whether the current time should be included in output. More...
 
std::string timeFormat ()
 Gets the format used printing the time. More...
 
void setTimeFormat (const std::string &timeFormat)
 Sets the format used printing the time. More...
 
Line verbose (const std::string &context="")
 Creates a new Line object with the Level Verbose. Once this object is destroyed, the content will be sent to the outputs. When logging to console, messages with this level will be sent to cout. More...
 
Line debug (const std::string &context="")
 Creates a new Line object with the Level Debug. Once this object is destroyed, the content will be sent to the outputs. When logging to console, messages with this level will be sent to cout. More...
 
Line info (const std::string &context="")
 Creates a new Line object with the Level Info. Once this object is destroyed, the content will be sent to the outputs. When logging to console, messages with this level will be sent to cout. More...
 
Line warning (const std::string &context="")
 Creates a new Line object with the Level Info. Once this object is destroyed, the content will be sent to the outputs. When logging to console, messages with this level will be sent to cerr. More...
 
Line error (const std::string &context="")
 Creates a new Line object with the Level Error. Once this object is destroyed, the content will be sent to the outputs. When logging to console, messages with this level will be sent to cerr. More...
 

Detailed Description

Logger namespace. Contains all available functions and classes.

Enumeration Type Documentation

◆ Level

Levels for filtering messages based on importance.

Enumerator
Verbose 

Used for low-level debugging information. When logging to console, messages with this level will be sent to cout.

Debug 

Used for debugging information. When logging to console, messages with this level will be sent to cout.

Info 

Used for important information. When logging to console, messages with this level will be sent to cout.

Warning 

Used for logging non-critical problems. When logging to console, messages with this level will be sent to cerr.

Error 

Used for logging critical problems. When logging to console, messages with this level will be sent to cerr.

Off 

Used for disabling outputs.

Function Documentation

◆ consoleLevel()

Level logger::consoleLevel ( )

Gets the minimum Level for console output.

Returns
The minumum Level for console output. Log messages with a lower Level won't be written to the console.

◆ contextLength()

int logger::contextLength ( )

Gets the context lenght.

Returns
The context length. Contexts given to the message functions are adjusted to this number of characters.

◆ debug()

Line logger::debug ( const std::string &  context = "")

Creates a new Line object with the Level Debug. Once this object is destroyed, the content will be sent to the outputs. When logging to console, messages with this level will be sent to cout.

Parameters
contextThe context in which the message is logged, allowing for more informative output. This could be the current function, for example.
Returns
A Line object, used for piping content.

◆ enable()

void logger::enable ( const Level &  consoleLevel = Info,
const Level &  fileLevel = Off,
const std::string &  logFileFormat = "log/%Y-%m-%d-%H-%M-%S.txt" 
)

Enables the logger with the given minimum Levels. Call again to change these settings. This results in a new log file being generated, if file logging is enabled.

Parameters
consoleLevelMinimum Level for logging to console. Log messages with a lower Level won't be written to the console.
fileLevelMinimum Level for logging to file. Log messages with a lower Level won't be written to the log file.
logFileFormatNaming scheme for log files, see https://en.cppreference.com/w/cpp/io/manip/put_time for syntax.

◆ enabled()

bool logger::enabled ( )

Checks if the logger is enabled.

Returns
True if the logger is enabled, false otherwise.

◆ error()

Line logger::error ( const std::string &  context = "")

Creates a new Line object with the Level Error. Once this object is destroyed, the content will be sent to the outputs. When logging to console, messages with this level will be sent to cerr.

Parameters
contextThe context in which the message is logged, allowing for more informative output. This could be the current function, for example.
Returns
A Line object, used for piping content.

◆ fileLevel()

Level logger::fileLevel ( )

Gets the minimum Level for file output.

Returns
The minumum Level for file output. Log messages with a lower Level won't be written to the log file.

◆ info()

Line logger::info ( const std::string &  context = "")

Creates a new Line object with the Level Info. Once this object is destroyed, the content will be sent to the outputs. When logging to console, messages with this level will be sent to cout.

Parameters
contextThe context in which the message is logged, allowing for more informative output. This could be the current function, for example.
Returns
A Line object, used for piping content.

◆ logFile()

std::string logger::logFile ( )

Gets the output file for file logging.

Returns
The current output file, or an empty string if file logging is disabled.

◆ printTime()

bool logger::printTime ( )

Checks whether the current time is included in output.

Returns
True if the time is printed, false otherwise.

◆ setContextLength()

void logger::setContextLength ( const int &  contextLength)

Sets the context lenght.

Parameters
contextLengthThe context length. Contexts given to the message functions are adjusted to this number of characters.

◆ setPrintTime()

void logger::setPrintTime ( const bool &  printTime)

Sets whether the current time should be included in output.

Parameters
printTimeTrue to print the time, false otherwise.

◆ setTimeFormat()

void logger::setTimeFormat ( const std::string &  timeFormat)

Sets the format used printing the time.

Returns
The time format, as described here: https://en.cppreference.com/w/cpp/io/manip/put_time

◆ timeFormat()

std::string logger::timeFormat ( )

Gets the format used printing the time.

Returns
The time format.

◆ verbose()

Line logger::verbose ( const std::string &  context = "")

Creates a new Line object with the Level Verbose. Once this object is destroyed, the content will be sent to the outputs. When logging to console, messages with this level will be sent to cout.

Parameters
contextThe context in which the message is logged, allowing for more informative output. This could be the current function, for example.
Returns
A Line object, used for piping content.

◆ warning()

Line logger::warning ( const std::string &  context = "")

Creates a new Line object with the Level Info. Once this object is destroyed, the content will be sent to the outputs. When logging to console, messages with this level will be sent to cerr.

Parameters
contextThe context in which the message is logged, allowing for more informative output. This could be the current function, for example.
Returns
A Line object, used for piping content.