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