wex v24.10.0
Public Types | Public Member Functions | Static Public Member Functions | List of all members
wex::log Class Reference

This class offers logging. More...

#include <wex/core/log.h>

Public Types

enum class  level_t {
  TRACE , DEBUG , INFO , WARNING ,
  ERRORS , FATAL , STATUS , OFF
}
 The log levels supported. More...
 

Public Member Functions

 log (const std::string &topic=std::string())
 Default constructor.
 
 log (const std::exception &)
 Constructor for error level from a std exception.
 
 log (const pugi::xml_parse_result &)
 Constructor for error level from a pugi parse result.
 
 ~log ()
 Destructor, flushes stringstream to logging.
 
logoperator<< (bool)
 Supported loggers.
 
logoperator<< (int)
 Logs int according to level.
 
logoperator<< (unsigned int)
 Logs unsigned int according to level.
 
logoperator<< (size_t)
 Logs size_t according to level.
 
logoperator<< (long)
 Logs long according to level.
 
logoperator<< (long long)
 Logs long long according to level.
 
logoperator<< (char)
 Logs char according to level.
 
logoperator<< (char *)
 Logs char* according to level.
 
logoperator<< (const std::stringstream &ss)
 Logs stringstream according to level.
 
logoperator<< (const std::string &)
 Logs string according to level.
 
logoperator<< (const char *)
 Logs char* according to level.
 
logoperator<< (const wchar_t *)
 Logs char* according to level.
 
template<std::size_t N>
logoperator<< (const std::bitset< N > &b)
 Logs a bitset according to level.
 
logoperator<< (const pugi::xml_node &)
 Logs pugi according to level.
 
template<typename T >
logoperator<< (const T &t)
 Logs template class T according to level.
 
const std::string get () const
 Returns topic and current logging.
 

Static Public Member Functions

static void on_init (level_t loglevel=level_t_def(), const std::string &logfile=std::string())
 Initializes logging, and optionally sets logfile.
 
static level_t get_level ()
 Return current filter log level.
 
static std::string get_level_info ()
 Returns info for log levels.
 
static level_t level_t_def ()
 Returns default log level.
 
static const std::string path ()
 Returns path for actual logfile used.
 
static void set_level (level_t loglevel)
 Sets filter log level.
 
static log debug (const std::string &topic=std::string())
 Builds a debug level logger.
 
static log fatal (const std::string &topic=std::string())
 Builds a fatal level logger.
 
static log info (const std::string &topic=std::string())
 Builds a info level logger.
 
static log status (const std::string &topic=std::string())
 Builds a status level logger.
 
static log trace (const std::string &topic=std::string())
 Builds a trace level logger.
 
static log warning (const std::string &topic=std::string())
 Builds a warning level logger.
 

Detailed Description

This class offers logging.

Member Enumeration Documentation

◆ level_t

enum class wex::log::level_t
strong

The log levels supported.

The order should follow boost::log. See <boost/log/trivial.hpp>

Enumerator
TRACE 

trace level logging (most verbose)

DEBUG 

debug level

INFO 

info level

WARNING 

warning level

ERRORS 

error level

FATAL 

fatal level

STATUS 

from wxLog

OFF 

no logging

Constructor & Destructor Documentation

◆ log()

wex::log::log ( const std::string & topic = std::string())
explicit

Default constructor.

This prepares a error level logging.

Member Function Documentation

◆ on_init()

static void wex::log::on_init ( level_t loglevel = level_t_def(),
const std::string & logfile = std::string() )
static

Initializes logging, and optionally sets logfile.

Should be called before constructing a log object. The wex::cmdline_imp or wex::app::OnInit takes care of this.

Parameters
loglevelloglevel
logfilelogfile, empty string uses a default logfile

◆ operator<<() [1/2]

log & wex::log::operator<< ( bool )

Supported loggers.

Logs bool according to level.

◆ operator<<() [2/2]

template<typename T >
log & wex::log::operator<< ( const T & t)
inline

Logs template class T according to level.

You need a log method inside your template class.