#include <einhard.hpp>
A Logger object can be used to output messages to stdout.
The Logger object is created with a certain verbosity. All messages of a more verbose LogLevel will be filtered out. The way the class is build this can happen at compile time up to the level restriction given by the template parameter.
The class can automatically detect non-tty output and will not colorize output in that case.
Definition at line 347 of file einhard.hpp.
Public Member Functions | |
Logger (const LogLevel verbosity=WARN) | |
Create a new Logger object. More... | |
Logger (const LogLevel verbosity, const bool colorize) | |
Create a new Logger object explicitly selecting whether to colorize the output or not. More... | |
void | setAreaName (const char *name) |
Set an area name. More... | |
EINHARD_ALWAYS_INLINE_ void | setAreaName (const std::string &name) |
OutputFormatter | trace () const |
Access to the trace message stream. More... | |
template<typename... Ts> | |
void | trace (Ts &&... args) const noexcept |
OutputFormatter | debug () const |
Access to the debug message stream. More... | |
template<typename... Ts> | |
void | debug (Ts &&... args) const noexcept |
OutputFormatter | info () const |
Access to the info message stream. More... | |
template<typename... Ts> | |
void | info (Ts &&... args) const noexcept |
OutputFormatter | warn () const |
Access to the warning message stream. More... | |
template<typename... Ts> | |
void | warn (Ts &&... args) const noexcept |
OutputFormatter | error () const |
Access to the error message stream. More... | |
template<typename... Ts> | |
void | error (Ts &&... args) const noexcept |
OutputFormatter | fatal () const |
Access to the fatal message stream. More... | |
template<typename... Ts> | |
void | fatal (Ts &&... args) const noexcept |
Will print stacktrace. More... | |
template<LogLevel LEVEL> | |
bool | isEnabled () const noexcept |
void | setVerbosity (LogLevel verbosity) noexcept |
Modify the verbosity of the Logger. More... | |
LogLevel | getVerbosity () const noexcept |
Retrieve the current log level. More... | |
char const * | getVerbosityString () const |
Retrieve a human readable representation of the current log level. More... | |
void | setColorize (bool colorize) noexcept |
Select whether the output stream should be colorized. More... | |
bool | getColorize () const noexcept |
Check whether the output stream is colorized. More... | |
Private Attributes | |
char | areaName [32 - sizeof(LogLevel) - sizeof(bool)] = {'\0'} |
LogLevel | verbosity |
bool | colorize_stdout |
bool | colorize_stderr |
|
inline |
Create a new Logger object.
The object will automatically colorize output on ttys and not colorize output on non ttys.
Definition at line 362 of file einhard.hpp.
|
inline |
Create a new Logger object explicitly selecting whether to colorize the output or not.
Be aware that if output colorization is selected output will even be colorized if output is to a non tty.
Definition at line 375 of file einhard.hpp.
|
inline |
Set an area name.
This will be printed after the LogLevel to identify the place in the code where the output is coming from. This can be used to identify the different Logger objects in the log output.
name | A string. Only the first 30, or so, characters will be used. The rest will not be displayed. You can reset the name with an empty string. |
Definition at line 387 of file einhard.hpp.
|
inline |
Definition at line 394 of file einhard.hpp.
|
inline |
|
inlinenoexcept |
Definition at line 416 of file einhard.hpp.
|
inline |
|
inlinenoexcept |
Definition at line 442 of file einhard.hpp.
|
inline |
|
inlinenoexcept |
Definition at line 459 of file einhard.hpp.
|
inline |
|
inlinenoexcept |
Definition at line 475 of file einhard.hpp.
|
inline |
|
inlinenoexcept |
Definition at line 491 of file einhard.hpp.
|
inline |
|
inlinenoexcept |
|
inlinenoexcept |
Definition at line 520 of file einhard.hpp.
|
inlinenoexcept |
Modify the verbosity of the Logger.
Be aware that the verbosity can not be increased over the level given by the template parameter
Definition at line 535 of file einhard.hpp.
|
inlinenoexcept |
Retrieve the current log level.
If you want to check whether messages of a certain LogLevel will be output the method isEnabled() should be preffered.
Definition at line 545 of file einhard.hpp.
|
inline |
Retrieve a human readable representation of the current log level.
Definition at line 552 of file einhard.hpp.
|
inlinenoexcept |
Select whether the output stream should be colorized.
Definition at line 559 of file einhard.hpp.
|
inlinenoexcept |
Check whether the output stream is colorized.
Definition at line 567 of file einhard.hpp.
|
private |
Definition at line 350 of file einhard.hpp.
|
private |
Definition at line 351 of file einhard.hpp.
|
private |
Definition at line 352 of file einhard.hpp.
|
private |
Definition at line 353 of file einhard.hpp.