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 );
 
  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;
 
A stream modifier that allows to colorize the log output.
 
EINHARD_ALWAYS_INLINE_ Color(bool r) noexcept
 
EINHARD_ALWAYS_INLINE_ bool resetColor() const noexcept
 
EINHARD_ALWAYS_INLINE_ Color() noexcept
The default color modifier only affects the next object in the stream.
 
EINHARD_ALWAYS_INLINE_ char const  * ansiCode() const noexcept
 
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 ...
 
A Logger object can be used to output messages to stdout.
 
Logger(const LogLevel verbosity=WARN)
Create a new Logger object.
 
EINHARD_ALWAYS_INLINE_ void setAreaName(const std::string &name)
 
void info(Ts &&... args) const noexcept
 
void setVerbosity(LogLevel verbosity) noexcept
Modify the verbosity of the Logger.
 
OutputFormatter error() const
Access to the error message stream.
 
void fatal(Ts &&... args) const noexcept
Will print stacktrace.
 
void debug(Ts &&... args) const noexcept
 
Logger(const LogLevel verbosity, const bool colorize)
Create a new Logger object explicitly selecting whether to colorize the output or not.
 
OutputFormatter fatal() const
Access to the fatal message stream.
 
char const  * getVerbosityString() const
Retrieve a human readable representation of the current log level.
 
OutputFormatter info() const
Access to the info message stream.
 
void error(Ts &&... args) const noexcept
 
bool isEnabled() const noexcept
 
void warn(Ts &&... args) const noexcept
 
LogLevel getVerbosity() const noexcept
Retrieve the current log level.
 
OutputFormatter debug() const
Access to the debug message stream.
 
OutputFormatter trace() const
Access to the trace message stream.
 
void setAreaName(const char *name)
Set an area name.
 
char areaName[32 - sizeof(LogLevel) - sizeof(bool)]
 
void setColorize(bool colorize) noexcept
Select whether the output stream should be colorized.
 
OutputFormatter warn() const
Access to the warning message stream.
 
void trace(Ts &&... args) const noexcept
 
bool getColorize() const noexcept
Check whether the output stream is colorized.
 
EINHARD_ALWAYS_INLINE_ UnconditionalOutput(bool colorize_, const char *areaName, std::integral_constant< LogLevel, VERBOSITY >)
 
EINHARD_ALWAYS_INLINE_ UnconditionalOutput(bool colorize_)
 
void doInit(const char *areaName)
 
EINHARD_ALWAYS_INLINE_ UnconditionalOutput & operator<<(const T &msg)
 
EINHARD_ALWAYS_INLINE_ UnconditionalOutput & operator<<(std::ostream &(*manip)(std::ostream &))
 
void doCleanup(std::FILE *outfile=stdout) noexcept
 
UnconditionalOutput & operator<<(const Color< T > &col)
 
#define EINHARD_ALWAYS_INLINE_
 
#define _COLOR(name, code)
 
This namespace contains all objects required for logging using Einhard.
 
LogLevel getLogLevel(const std::string &level)
Compares the string level against the strings for LogLevel and returns the one it matches.
 
const char * colorForLogLevel() noexcept
 
char const VERSION[]
Version string of the Einhard library.
 
LogLevel
Specification of the message severity.
 
@ TRACE
The lowes severity for messages describing the program flow.
 
@ OFF
If selected no messages will be output.
 
@ FATAL
Messages that indicate terminal application failure.
 
@ INFO
Messages of informational nature, expected processing time e.g.
 
const char * getLogLevelString() noexcept
Retrieve a human readable representation of the given log level value.