69 #include "stacktrace.h" 77 #define EINHARD_ALWAYS_INLINE_ __attribute__((always_inline)) 79 #define EINHARD_ALWAYS_INLINE_ 86 #define EINHARD_NO_THREAD_LOCAL 1 142 template <typename Parent> class
Color 157 return Parent::ANSI();
170 #define _COLOR( name, code ) \ 173 static char const *ANSI() noexcept \ 175 return "\33[" code "m"; \ 178 typedef Color<name##_t_> name 210 std::ostream &( * )( std::ostream & ) ) noexcept
221 #ifdef EINHARD_NO_THREAD_LOCAL 223 std::ostringstream realOut;
233 template <LogLevel VERBOSITY>
235 std::integral_constant<LogLevel, VERBOSITY> )
238 doInit<VERBOSITY>( areaName );
245 *
out << col.ansiCode();
264 void doCleanup(std::FILE *outfile = stdout) noexcept;
270 template <LogLevel VERBOSITY>
void doInit(
const char *areaName );
288 template <LogLevel VERBOSITY>
290 const char *areaName,
291 std::integral_constant<LogLevel, VERBOSITY>,
292 std::FILE *outfile_ = stdout )
297 doInit<VERBOSITY>( areaName );
347 template<LogLevel MAX = ALL>
class Logger 406 template <
typename... Ts>
void trace( Ts &&... ) const noexcept
413 std::integral_constant<LogLevel, TRACE>()};
416 template <
typename... Ts>
void trace( Ts &&... args )
const noexcept
418 if( isEnabled<TRACE>() )
421 std::integral_constant<LogLevel, TRACE>()};
422 auto &&unused = {&( o << args )...};
433 template <
typename... Ts>
void debug( Ts &&... ) const noexcept
440 std::integral_constant<LogLevel, DEBUG>()};
442 template <
typename... Ts>
void debug( Ts &&... args )
const noexcept
444 if( isEnabled<DEBUG>() )
447 std::integral_constant<LogLevel, DEBUG>()};
448 auto &&unused = {&( o << args )...};
457 std::integral_constant<LogLevel, INFO>()};
459 template <
typename... Ts>
void info( Ts &&... args )
const noexcept
461 if( isEnabled<INFO>() )
464 std::integral_constant<LogLevel, INFO>()};
465 auto &&unused = {&( o << args )...};
473 std::integral_constant<LogLevel, WARN>(), stderr};
475 template <
typename... Ts>
void warn( Ts &&... args )
const noexcept
477 if( isEnabled<WARN>() )
480 std::integral_constant<LogLevel, WARN>()};
481 auto &&unused = {&( o << args )...};
489 std::integral_constant<LogLevel, ERROR>(), stderr};
491 template <
typename... Ts>
void error( Ts &&... args )
const noexcept
493 if( isEnabled<ERROR>() )
496 std::integral_constant<LogLevel, ERROR>()};
497 auto &&unused = {&( o << args )...};
505 std::integral_constant<LogLevel, FATAL>(), stderr};
508 template <
typename... Ts>
void fatal( Ts &&... args )
const noexcept
510 if( isEnabled<FATAL>() )
513 std::integral_constant<LogLevel, FATAL>()};
514 auto &&unused = {&( o << args )...};
516 print_stacktrace(stderr, 63, 2);
520 template <LogLevel LEVEL>
bool isEnabled() const noexcept
527 return ( MAX <= LEVEL &&
verbosity <= LEVEL );
561 this->colorize_stdout = colorize;
562 this->colorize_stderr = colorize;
OutputFormatter error() const
Access to the error message stream.
void setAreaName(const char *name)
Set an area name.
Logger(const LogLevel verbosity, const bool colorize)
Create a new Logger object explicitly selecting whether to colorize the output or not...
bool getColorize() const noexcept
Check whether the output stream is colorized.
OutputFormatter trace() const
Access to the trace message stream.
bool isEnabled() const noexcept
void debug(Ts &&... args) const noexcept
The lowes severity for messages describing the program flow.
const char * colorForLogLevel() noexcept
EINHARD_ALWAYS_INLINE_ void setAreaName(const std::string &name)
#define _COLOR(name, code)
EINHARD_ALWAYS_INLINE_ UnconditionalOutput & operator<<(std::ostream &(*manip)(std::ostream &))
If selected no messages will be output.
OutputFormatter debug() const
Access to the debug message stream.
OutputFormatter fatal() const
Access to the fatal message stream.
EINHARD_ALWAYS_INLINE_ UnconditionalOutput & operator<<(const T &msg)
#define EINHARD_ALWAYS_INLINE_
void warn(Ts &&... args) const noexcept
OutputFormatter warn() const
Access to the warning message stream.
Messages of informational nature, expected processing time e.g.
EINHARD_ALWAYS_INLINE_ UnconditionalOutput(bool colorize_, const char *areaName, std::integral_constant< LogLevel, VERBOSITY >)
EINHARD_ALWAYS_INLINE_ UnconditionalOutput(bool colorize_)
EINHARD_ALWAYS_INLINE_ Color< Parent > operator~() const noexcept
With the ~ operator the color modifier affects the rest of the stream (or until another color object ...
LogLevel getVerbosity() const noexcept
Retrieve the current log level.
EINHARD_ALWAYS_INLINE_ bool resetColor() const noexcept
const char * getLogLevelString() noexcept
Retrieve a human readable representation of the given log level value.
Logger(const LogLevel verbosity=WARN)
Create a new Logger object.
void trace(Ts &&... args) const noexcept
void doInit(const char *areaName)
void fatal(Ts &&... args) const noexcept
Will print stacktrace.
EINHARD_ALWAYS_INLINE_ Color() noexcept
The default color modifier only affects the next object in the stream.
char const * getVerbosityString() const
Retrieve a human readable representation of the current log level.
EINHARD_ALWAYS_INLINE_ Color(bool r) noexcept
This namespace contains all objects required for logging using Einhard.
void setColorize(bool colorize) noexcept
Select whether the output stream should be colorized.
A Logger object can be used to output messages to stdout.
OutputFormatter info() const
Access to the info message stream.
void setVerbosity(LogLevel verbosity) noexcept
Modify the verbosity of the Logger.
Messages that indicate terminal application failure.
A stream modifier that allows to colorize the log output.
void error(Ts &&... args) const noexcept
char areaName[32 - sizeof(LogLevel) - sizeof(bool)]
LogLevel
Specification of the message severity.
UnconditionalOutput & operator<<(const Color< T > &col)
LogLevel getLogLevel(const std::string &level)
Compares the string level against the strings for LogLevel and returns the one it matches...
EINHARD_ALWAYS_INLINE_ char const * ansiCode() const noexcept
void info(Ts &&... args) const noexcept
void doCleanup(std::FILE *outfile=stdout) noexcept
char const VERSION[]
Version string of the Einhard library.