MercuryDPM  Beta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Logger< L > Class Template Reference

Logger. More...

#include <Logger.h>

Public Member Functions

 Logger (const std::string name)
 constructor More...
 
 ~Logger ()
 destructor More...
 
template<Log LOGLEVEL, typename... Args>
std::enable_if<!((L< LOGLEVEL)||(MERCURY_LOGLEVEL
< LOGLEVEL)), void >::type 
operator() (const LL< LOGLEVEL > log UNUSED, const std::string &format, Args &&...arg)
 
template<Log LOGLEVEL, typename... Args>
std::enable_if< L< LOGLEVEL||MERCURY_LOGLEVEL
< LOGLEVEL, void >::type
operator()(const LL< LOGLEVEL >
log UNUSED, const std::string
&format UNUSED, Args &&...arg
UNUSED){}template< Log
LOGLEVEL, typename...Args >
typename std::enable_if<!((L
< LOGLEVEL)||(MERCURY_LOGLEVEL
< LOGLEVEL)), void >::type
operator()(const LL< LOGLEVEL >
log UNUSED, const char
*format, Args &&...arg){std::stringstream
msgstream;createMessage(msgstream,
format, arg...);if(LOGLEVEL
<=Log::FATAL){loggerOutput->
onFatal(module, msgstream.str());}else
if(LOGLEVEL<=Log::ERROR){loggerOutput-> 
onError (module, msgstream.str())
 
else if (LOGLEVEL<=Log::WARN)
 
else if (LOGLEVEL<=Log::INFO)
 
else if (LOGLEVEL<=Log::VERBOSE)
 
template<Log LOGLEVEL, typename... Args>
std::enable_if< L< LOGLEVEL||MERCURY_LOGLEVEL
< LOGLEVEL, void >::type
operator()(const LL< LOGLEVEL >
log UNUSED, const char
*format UNUSED, Args &&...arg
UNUSED){}template
< typename...Args > void log(const
Log loglevel, const
std::string &format, Args
&&...arg){if(loglevel<=L||loglevel
<=MERCURY_LOGLEVEL){std::stringstream
msgstream;createMessage(msgstream,
format.c_str(), arg...);if(loglevel
<=Log::FATAL){loggerOutput->
onFatal(module, msgstream.str());}else
if(loglevel<=Log::ERROR){loggerOutput-> 
onError (module, msgstream.str())
 
else if (loglevel<=Log::WARN)
 
else if (loglevel<=Log::INFO)
 
else if (loglevel<=Log::VERBOSE)
 

Public Attributes

 else
 

Private Member Functions

template<typename Arg1 , typename... Args>
void createMessage (std::stringstream &msg, const char *fmt, Arg1 &&arg, Args &&...args)
 Actual implementation to recursively replace all the '' signs by actual values. More...
 
template<typename Arg1 >
void createMessage (std::stringstream &msg, const char *fmt, Arg1 &&arg)
 Terminating case / argument call. More...
 
void createMessage (std::stringstream &msg, const char *message)
 Terminating case / no argument call. More...
 

Private Attributes

const std::string module
 The module name of this actual logger. More...
 

Detailed Description

template<Log L = Log::DEFAULT>
class Logger< L >

Logger.

  • L The log level. Messages of higher level are ignored

Usage: logger(FATAL, "Error in (here) because % < %!\n", var1, var2);

Define custom loggers by: #ifndef HG_LOGLEVEL_CUSTOMMOD #define HG_LOGLEVEL_CUSTOMMOD Log::Debug #endif Logger<HG_LOGLEVEL_CUSTOMMOD> customLogger;

Definition at line 161 of file Logger.h.

Constructor & Destructor Documentation

template<Log L = Log::DEFAULT>
Logger< L >::Logger ( const std::string  name)
inline

constructor

  • name The name in this module used in output messages.

Definition at line 285 of file Logger.h.

285 : module(name) { }
const std::string module
The module name of this actual logger.
Definition: Logger.h:277
template<Log L = Log::DEFAULT>
Logger< L >::~Logger ( )
inline

destructor

Definition at line 289 of file Logger.h.

289 {}

Member Function Documentation

template<Log L = Log::DEFAULT>
template<typename Arg1 , typename... Args>
void Logger< L >::createMessage ( std::stringstream &  msg,
const char *  fmt,
Arg1 &&  arg,
Args &&...  args 
)
inlineprivate

Actual implementation to recursively replace all the '' signs by actual values.

Definition at line 387 of file Logger.h.

Referenced by Logger< L >::operator()().

389  {
390  bool doSkipNext = false;
391  while (*fmt != '%' && !doSkipNext)
392  {
393  doSkipNext = false;
394  //Make sure we're not running past the end of our formatting string.
395  if (*fmt == '\0')
396  return;
397 
398  if (*fmt == '\\')
399  { //Escape for the %sign
400  doSkipNext = true;
401  }
402  else
403  {
404  msg << *fmt;
405  fmt++;
406  }
407  }
408 
409  fmt++; //Consume the % sign
410  msg << arg;
411  createMessage(msg, fmt, args...); //and recursively call ourselve / the method below.
412  }
void createMessage(std::stringstream &msg, const char *fmt, Arg1 &&arg, Args &&...args)
Actual implementation to recursively replace all the '' signs by actual values.
Definition: Logger.h:387
template<Log L = Log::DEFAULT>
template<typename Arg1 >
void Logger< L >::createMessage ( std::stringstream &  msg,
const char *  fmt,
Arg1 &&  arg 
)
inlineprivate

Terminating case / argument call.

Definition at line 418 of file Logger.h.

419  {
420  bool doSkipNext = false;
421  while (*fmt != '%' && !doSkipNext)
422  {
423  doSkipNext = false;
424  if (*fmt == '\0') // End of string
425  return;
426 
427  if (*fmt == '\\')
428  { //Escape for the %sign
429  doSkipNext = true;
430  }
431  else
432  { //invoke the replacement
433  msg << *fmt;
434  fmt++;
435  }
436  }
437  fmt++; //Consume the % sign
438  msg << arg;
439  while (*fmt != '\0')
440  { //And print the end of the message!
441  msg << *fmt;
442  fmt++;
443  }
444  }
template<Log L = Log::DEFAULT>
void Logger< L >::createMessage ( std::stringstream &  msg,
const char *  message 
)
inlineprivate

Terminating case / no argument call.

Definition at line 450 of file Logger.h.

451  {
452  msg << message;
453  }
template<Log L = Log::DEFAULT>
else Logger< L >::if ( LOGLEVEL<=Log::WARN  )
inline

Definition at line 339 of file Logger.h.

339  {
340  loggerOutput->onWarn(module, msgstream.str());
341  } else if (LOGLEVEL <= Log::INFO) {
LoggerOutput * loggerOutput
Declaration of the output functions. If the output needs to be redirected, please swap the loggerOutp...
Definition: Logger.cc:110
const std::string module
The module name of this actual logger.
Definition: Logger.h:277
std::function< void(std::string, std::string)> onWarn
Definition: Logger.h:144
template<Log L = Log::DEFAULT>
else Logger< L >::if ( LOGLEVEL<=Log::INFO  )
inline

Definition at line 341 of file Logger.h.

341  {
342  loggerOutput->onInfo(module, msgstream.str());
343  } else if (LOGLEVEL <= Log::VERBOSE) {
LoggerOutput * loggerOutput
Declaration of the output functions. If the output needs to be redirected, please swap the loggerOutp...
Definition: Logger.cc:110
const std::string module
The module name of this actual logger.
Definition: Logger.h:277
std::function< void(std::string, std::string)> onInfo
Definition: Logger.h:145
template<Log L = Log::DEFAULT>
else Logger< L >::if ( LOGLEVEL<=Log::VERBOSE  )
inline

Definition at line 343 of file Logger.h.

343  {
344  loggerOutput->onVerbose(module, msgstream.str());
345  } else {
LoggerOutput * loggerOutput
Declaration of the output functions. If the output needs to be redirected, please swap the loggerOutp...
Definition: Logger.cc:110
const std::string module
The module name of this actual logger.
Definition: Logger.h:277
std::function< void(std::string, std::string)> onVerbose
Definition: Logger.h:146
template<Log L = Log::DEFAULT>
else Logger< L >::if ( loglevel<=Log::WARN  )
inline

Definition at line 370 of file Logger.h.

370  {
371  loggerOutput->onWarn(module, msgstream.str());
372  } else if (loglevel <= Log::INFO) {
LoggerOutput * loggerOutput
Declaration of the output functions. If the output needs to be redirected, please swap the loggerOutp...
Definition: Logger.cc:110
const std::string module
The module name of this actual logger.
Definition: Logger.h:277
std::function< void(std::string, std::string)> onWarn
Definition: Logger.h:144
template<Log L = Log::DEFAULT>
else Logger< L >::if ( loglevel<=Log::INFO  )
inline

Definition at line 372 of file Logger.h.

372  {
373  loggerOutput->onInfo(module, msgstream.str());
374  } else if (loglevel <= Log::VERBOSE) {
LoggerOutput * loggerOutput
Declaration of the output functions. If the output needs to be redirected, please swap the loggerOutp...
Definition: Logger.cc:110
const std::string module
The module name of this actual logger.
Definition: Logger.h:277
std::function< void(std::string, std::string)> onInfo
Definition: Logger.h:145
template<Log L = Log::DEFAULT>
else Logger< L >::if ( loglevel<=Log::VERBOSE  )
inline

Definition at line 374 of file Logger.h.

374  {
375  loggerOutput->onVerbose(module, msgstream.str());
376  } else {
LoggerOutput * loggerOutput
Declaration of the output functions. If the output needs to be redirected, please swap the loggerOutp...
Definition: Logger.cc:110
const std::string module
The module name of this actual logger.
Definition: Logger.h:277
std::function< void(std::string, std::string)> onVerbose
Definition: Logger.h:146
template<Log L = Log::DEFAULT>
template<Log LOGLEVEL, typename... Args>
std::enable_if<L < LOGLEVEL || MERCURY_LOGLEVEL < LOGLEVEL, void>::type operator()(const LL<LOGLEVEL> log UNUSED, const std::string& format UNUSED, Args&&... arg UNUSED) { } template<Log LOGLEVEL, typename... Args> typename std::enable_if<!((L < LOGLEVEL) || (MERCURY_LOGLEVEL < LOGLEVEL)), void>::type operator()(const LL<LOGLEVEL> log UNUSED, const char * format, Args&&... arg) { std::stringstream msgstream; createMessage(msgstream, format, arg...); if (LOGLEVEL <= Log::FATAL) { loggerOutput->onFatal(module, msgstream.str()); } else if (LOGLEVEL <= Log::ERROR) { loggerOutput-> Logger< L >::onError ( module  ,
msgstream.  str() 
)
template<Log L = Log::DEFAULT>
template<Log LOGLEVEL, typename... Args>
std::enable_if<L < LOGLEVEL || MERCURY_LOGLEVEL < LOGLEVEL, void>::type operator()(const LL<LOGLEVEL> log UNUSED, const char * format UNUSED, Args&&... arg UNUSED) { } template<typename... Args> void log(const Log loglevel, const std::string& format, Args&&... arg) { if (loglevel <= L || loglevel <= MERCURY_LOGLEVEL) { std::stringstream msgstream; createMessage(msgstream, format.c_str(), arg...); if (loglevel <= Log::FATAL) { loggerOutput->onFatal(module, msgstream.str()); } else if (loglevel <= Log::ERROR) { loggerOutput-> Logger< L >::onError ( module  ,
msgstream.  str() 
)
template<Log L = Log::DEFAULT>
template<Log LOGLEVEL, typename... Args>
std::enable_if<!((L < LOGLEVEL) || (MERCURY_LOGLEVEL < LOGLEVEL)), void>::type Logger< L >::operator() ( const LL< LOGLEVEL > log  UNUSED,
const std::string &  format,
Args &&...  arg 
)
inline

Definition at line 306 of file Logger.h.

References Logger< L >::createMessage(), ERROR, FATAL, INFO, Logger< L >::module, LoggerOutput::onDebug, LoggerOutput::onError, LoggerOutput::onFatal, LoggerOutput::onInfo, LoggerOutput::onVerbose, LoggerOutput::onWarn, VERBOSE, and WARN.

306  {
307  std::stringstream msgstream;
308  createMessage(msgstream, format.c_str(), arg...);
309  if (LOGLEVEL <= Log::FATAL) {
310  loggerOutput->onFatal(module, msgstream.str());
311  } else if (LOGLEVEL <= Log::ERROR) {
312  loggerOutput->onError(module, msgstream.str());
313  } else if (LOGLEVEL <= Log::WARN) {
314  loggerOutput->onWarn(module, msgstream.str());
315  } else if (LOGLEVEL <= Log::INFO) {
316  loggerOutput->onInfo(module, msgstream.str());
317  } else if (LOGLEVEL <= Log::VERBOSE) {
318  loggerOutput->onVerbose(module, msgstream.str());
319  } else {
320  loggerOutput->onDebug(module, msgstream.str());
321  }
322  }
LoggerOutput * loggerOutput
Declaration of the output functions. If the output needs to be redirected, please swap the loggerOutp...
Definition: Logger.cc:110
const std::string module
The module name of this actual logger.
Definition: Logger.h:277
std::function< void(std::string, std::string)> onWarn
Definition: Logger.h:144
std::function< void(std::string, std::string)> onVerbose
Definition: Logger.h:146
void createMessage(std::stringstream &msg, const char *fmt, Arg1 &&arg, Args &&...args)
Actual implementation to recursively replace all the '' signs by actual values.
Definition: Logger.h:387
std::function< void(std::string, std::string)> onError
Definition: Logger.h:143
std::function< void(std::string, std::string)> onDebug
Definition: Logger.h:147
std::function< void(std::string, std::string)> onInfo
Definition: Logger.h:145
std::function< void(std::string, std::string)> onFatal
Definition: Logger.h:142

Member Data Documentation

template<Log L = Log::DEFAULT>
Logger< L >::else
Initial value:
{
loggerOutput->onDebug(module, msgstream.str())

Definition at line 345 of file Logger.h.

template<Log L = Log::DEFAULT>
const std::string Logger< L >::module
private

The module name of this actual logger.

Definition at line 277 of file Logger.h.

Referenced by Logger< L >::operator()().


The documentation for this class was generated from the following file: