Static Public Member Functions | Public Member Functions | List of all members
Logger Class Reference

The main logger class. More...

#include <Logger.hpp>

Static Public Member Functions

static void configure (const std::string &configurationText, const std::map< std::string, std::string > &placeholders=std::map< std::string, std::string >())
 Flush all current logging streams and configure the logging system with the supplied configuration text. More...
 
static void configure (const std::shared_ptr< EnvironmentProperties > &configuration, const std::map< std::string, std::string > &placeholders=std::map< std::string, std::string >())
 Flush all current logging streams and configure the logging system with the supplied configuration. More...
 
static void flushAll ()
 Flush all logging streams. More...
 
static LoggergetLogger (std::string_view loggingNamespace) noexcept
 Get a reference to the instance of the logger identified by the supplied namespace. More...
 
static LoggerglobalLogger ()
 A predefined reference to the global logger. More...
 
static void lockConfiguration (bool throwOnReconfigure=false)
 Lock the configuration in order to prevent future reconfiguration. More...
 
static void registerLoggingStreamFactory (const std::string &scheme, LoggingStreamFactory factory)
 Register a logging stream factory. More...
 
static void resetConfiguration ()
 Flush all current logging streams and reconfigure the logging system to the default configuration. More...
 

Public Member Functions

void debug (const char *message) const
 Log a debug message. More...
 
void debug (std::string_view message) const
 Log a debug message. More...
 
template<typename ... ObjectT>
void debug (const char *message, const ObjectT &... object) const
 Log a debug message with parameters. More...
 
template<typename ... ObjectT>
void debug (std::string_view message, const ObjectT &... object) const
 Log a debug message with parameters. More...
 
void debug (const std::function< std::string()> &function) const
 Log a debug message via the supplied function. More...
 
void debug (const SourceCodeLocation &location, const char *message) const
 Log a debug message and the source code location of the log message call site. More...
 
void debug (const SourceCodeLocation &location, std::string_view message) const
 Log a debug message and the source code location of the log message call site. More...
 
template<typename ... ObjectT>
void debug (const SourceCodeLocation &location, const char *message, const ObjectT &... object) const
 Log a debug message with parameters and the source code location of the log message call site. More...
 
template<typename ... ObjectT>
void debug (const SourceCodeLocation &location, std::string_view message, const ObjectT &... object) const
 Log a debug message with parameters and the source code location of the log message call site. More...
 
void debug (const SourceCodeLocation &location, const std::function< std::string()> &function) const
 Log a debug message via the supplied function and the source code location of the log message call site. More...
 
bool debugEnabled () const
 Is debug level logging enabled for this logger. More...
 
bool enabled (LoggingLevel level) const
 Is logging at the specified level enabled for this logger. More...
 
void error (const char *message) const
 Log an error message. More...
 
void error (std::string_view message) const
 Log an error message. More...
 
template<typename ... ObjectT>
void error (const char *message, const ObjectT &... object) const
 Log an error message with parameters. More...
 
template<typename ... ObjectT>
void error (std::string_view message, const ObjectT &... object) const
 Log an error message with parameters. More...
 
void error (const std::function< std::string()> &function) const
 Log a error message via the supplied function. More...
 
void error (const SourceCodeLocation &location, const char *message) const
 Log an error message and the source code location of the log message call site. More...
 
void error (const SourceCodeLocation &location, std::string_view message) const
 Log an error message and the source code location of the log message call site. More...
 
template<typename ... ObjectT>
void error (const SourceCodeLocation &location, const char *message, const ObjectT &... object) const
 Log an error message with parameters and the source code location of the log message call site. More...
 
template<typename ... ObjectT>
void error (const SourceCodeLocation &location, std::string_view message, const ObjectT &... object) const
 Log an error message with parameters and the source code location of the log message call site. More...
 
void error (const SourceCodeLocation &location, const std::function< std::string()> &function) const
 Log an error message via the supplied function and the source code location of the log message call site. More...
 
bool errorEnabled () const
 Is error level logging enabled for this logger. More...
 
void flush () const
 Flush the streams associated with the logger. More...
 
bool flushes () const noexcept
 Returns true if the logger is auto-flushing. More...
 
std::string getConfiguration () const
 get the logger's configuration as a string (namespace and properties). More...
 
LoggingLevel getLevel () const noexcept
 Get the logging level of this logger. More...
 
std::string getNamespace () const
 Get the logging namespace of this logger. More...
 
void info (const char *message) const
 Log an info message. More...
 
void info (std::string_view message) const
 Log an info message. More...
 
template<typename ... ObjectT>
void info (const char *message, const ObjectT &... object) const
 Log an info message with parameters. More...
 
template<typename ... ObjectT>
void info (std::string_view message, const ObjectT &... object) const
 Log an info message with parameters. More...
 
void info (const std::function< std::string()> &function) const
 Log an info message via the supplied function. More...
 
void info (const SourceCodeLocation &location, const char *message) const
 Log an info message and the source code location of the log message call site. More...
 
void info (const SourceCodeLocation &location, std::string_view message) const
 Log an info message and the source code location of the log message call site. More...
 
template<typename ... ObjectT>
void info (const SourceCodeLocation &location, const char *message, const ObjectT &... object) const
 Log an info message with parameters and the source code location of the log message call site. More...
 
template<typename ... ObjectT>
void info (const SourceCodeLocation &location, std::string_view message, const ObjectT &... object) const
 Log an info message with parameters and the source code location of the log message call site. More...
 
void info (const SourceCodeLocation &location, const std::function< std::string()> &function) const
 Log an info message via the supplied function and the source code location of the log message call site. More...
 
bool infoEnabled () const
 Is info level logging enabled for this logger. More...
 
void log (LoggingLevel specifiedLevel, const char *message) const
 Log a message. More...
 
void log (LoggingLevel specifiedLevel, std::string_view message) const
 Log a message. More...
 
template<typename ... ObjectT>
void log (LoggingLevel specifiedLevel, const char *message, const ObjectT &... object) const
 Log a message with parameters. More...
 
template<typename ... ObjectT>
void log (LoggingLevel specifiedLevel, std::string_view message, const ObjectT &... object) const
 Log a message with parameters. More...
 
void log (LoggingLevel specifiedLevel, const std::function< std::string()> &function) const
 Log a error message via the supplied function. More...
 
void log (LoggingLevel specifiedLevel, const SourceCodeLocation &location, const char *message) const
 Log an error message and the source code location of the log message call site. More...
 
void log (LoggingLevel specifiedLevel, const SourceCodeLocation &location, std::string_view message) const
 Log an error message and the source code location of the log message call site. More...
 
template<typename ... ObjectT>
void log (LoggingLevel specifiedLevel, const SourceCodeLocation &location, const char *message, const ObjectT &... object) const
 Log an error message with parameters and the source code location of the log message call site. More...
 
template<typename ... ObjectT>
void log (LoggingLevel specifiedLevel, const SourceCodeLocation &location, std::string_view message, const ObjectT &... object) const
 Log an error message with parameters and the source code location of the log message call site. More...
 
void log (LoggingLevel specifiedLevel, const SourceCodeLocation &location, const std::function< std::string()> &function) const
 Log an error message via the supplied function and the source code location of the log message call site. More...
 
bool operator== (const Logger &logger) const
 Compare two loggers for equality. More...
 
void trace (const char *message) const
 Log a trace message. More...
 
void trace (std::string_view message) const
 Log a trace message. More...
 
template<typename ... ObjectT>
void trace (const char *message, const ObjectT &... object) const
 Log a trace message with parameters. More...
 
template<typename ... ObjectT>
void trace (std::string_view message, const ObjectT &... object) const
 Log a trace message with parameters. More...
 
void trace (const std::function< std::string()> &function) const
 Log a trace message via the supplied function. More...
 
void trace (const SourceCodeLocation &location, const char *message) const
 Log a trace message and the source code location of the log message call site. More...
 
void trace (const SourceCodeLocation &location, std::string_view message) const
 Log a trace message and the source code location of the log message call site. More...
 
template<typename ... ObjectT>
void trace (const SourceCodeLocation &location, const char *message, const ObjectT &... object) const
 Log a trace message with parameters and the source code location of the log message call site. More...
 
template<typename ... ObjectT>
void trace (const SourceCodeLocation &location, std::string_view message, const ObjectT &... object) const
 Log a trace message with parameters and the source code location of the log message call site. More...
 
void trace (const SourceCodeLocation &location, const std::function< std::string()> &function) const
 Log a trace message via the supplied function and the source code location of the log message call site. More...
 
bool traceEnabled () const
 Is trace level logging enabled for this logger. More...
 
void warn (const char *message) const
 Log a warn message. More...
 
void warn (std::string_view message) const
 Log a warn message. More...
 
template<typename ... ObjectT>
void warn (const char *message, const ObjectT &... object) const
 Log a warn message with parameters. More...
 
template<typename ... ObjectT>
void warn (std::string_view message, const ObjectT &... object) const
 Log a warn message with parameters. More...
 
void warn (const std::function< std::string()> &function) const
 Log a warn message via the supplied function. More...
 
void warn (const SourceCodeLocation &location, const char *message) const
 Log a warn message and the source code location of the log message call site. More...
 
void warn (const SourceCodeLocation &location, std::string_view message) const
 Log a warn message and the source code location of the log message call site. More...
 
template<typename ... ObjectT>
void warn (const SourceCodeLocation &location, const char *message, const ObjectT &... object) const
 Log a warn message with parameters and the source code location of the log message call site. More...
 
template<typename ... ObjectT>
void warn (const SourceCodeLocation &location, std::string_view message, const ObjectT &... object) const
 Log a warn message with parameters and the source code location of the log message call site. More...
 
void warn (const SourceCodeLocation &location, const std::function< std::string()> &function) const
 Log a warn message via the supplied function and the source code location of the log message call site. More...
 
bool warnEnabled () const
 Is warn level logging enabled for this logger. More...
 

Detailed Description

The main logger class.

All interaction with the logging system occurs through static methods in this class or instance methods called on Logger references obtained from the static Logger::getLogger method.

Member Function Documentation

◆ configure() [1/2]

static void configure ( const std::string &  configurationText,
const std::map< std::string, std::string > &  placeholders = std::map< std::string, std::string >() 
)
static

Flush all current logging streams and configure the logging system with the supplied configuration text.

Any placeholders supplied in the placeholders map will be used to expand any macros found in the configuration text.

This call will obtain a lock on the logging system mutex.

Parameters
configurationTextthe unparsed logging configuration
placeholderszero or more placeholders to be used to expand any macros present in the string value properties
Exceptions
LoggingConfigurationExceptionif logging reconfiguration has previously been locked.

◆ configure() [2/2]

static void configure ( const std::shared_ptr< EnvironmentProperties > &  configuration,
const std::map< std::string, std::string > &  placeholders = std::map< std::string, std::string >() 
)
static

Flush all current logging streams and configure the logging system with the supplied configuration.

Any placeholders supplied in the placeholders map will be used to expand any macros found in the configuration.

This call will obtain a lock on the logging system mutex.

Parameters
configurationthe pre-parsed logging configuration (normally from the injector)
placeholderszero or more placeholders to be used to expand any macros present in the string value properties
Exceptions
LoggingConfigurationExceptionif logging reconfiguration has previously been locked.

◆ debug() [1/10]

void debug ( const char *  message) const
inline

Log a debug message.

◆ debug() [2/10]

void debug ( std::string_view  message) const
inline

Log a debug message.

◆ debug() [3/10]

void debug ( const char *  message,
const ObjectT &...  object 
) const
inline

Log a debug message with parameters.

◆ debug() [4/10]

void debug ( std::string_view  message,
const ObjectT &...  object 
) const
inline

Log a debug message with parameters.

◆ debug() [5/10]

void debug ( const std::function< std::string()> &  function) const
inline

Log a debug message via the supplied function.

◆ debug() [6/10]

void debug ( const SourceCodeLocation location,
const char *  message 
) const
inline

Log a debug message and the source code location of the log message call site.

◆ debug() [7/10]

void debug ( const SourceCodeLocation location,
std::string_view  message 
) const
inline

Log a debug message and the source code location of the log message call site.

◆ debug() [8/10]

void debug ( const SourceCodeLocation location,
const char *  message,
const ObjectT &...  object 
) const
inline

Log a debug message with parameters and the source code location of the log message call site.

◆ debug() [9/10]

void debug ( const SourceCodeLocation location,
std::string_view  message,
const ObjectT &...  object 
) const
inline

Log a debug message with parameters and the source code location of the log message call site.

◆ debug() [10/10]

void debug ( const SourceCodeLocation location,
const std::function< std::string()> &  function 
) const
inline

Log a debug message via the supplied function and the source code location of the log message call site.

◆ debugEnabled()

bool debugEnabled ( ) const
inline

Is debug level logging enabled for this logger.

◆ enabled()

bool enabled ( LoggingLevel  level) const
inline

Is logging at the specified level enabled for this logger.

◆ error() [1/10]

void error ( const char *  message) const
inline

Log an error message.

◆ error() [2/10]

void error ( std::string_view  message) const
inline

Log an error message.

◆ error() [3/10]

void error ( const char *  message,
const ObjectT &...  object 
) const
inline

Log an error message with parameters.

◆ error() [4/10]

void error ( std::string_view  message,
const ObjectT &...  object 
) const
inline

Log an error message with parameters.

◆ error() [5/10]

void error ( const std::function< std::string()> &  function) const
inline

Log a error message via the supplied function.

◆ error() [6/10]

void error ( const SourceCodeLocation location,
const char *  message 
) const
inline

Log an error message and the source code location of the log message call site.

◆ error() [7/10]

void error ( const SourceCodeLocation location,
std::string_view  message 
) const
inline

Log an error message and the source code location of the log message call site.

◆ error() [8/10]

void error ( const SourceCodeLocation location,
const char *  message,
const ObjectT &...  object 
) const
inline

Log an error message with parameters and the source code location of the log message call site.

◆ error() [9/10]

void error ( const SourceCodeLocation location,
std::string_view  message,
const ObjectT &...  object 
) const
inline

Log an error message with parameters and the source code location of the log message call site.

◆ error() [10/10]

void error ( const SourceCodeLocation location,
const std::function< std::string()> &  function 
) const
inline

Log an error message via the supplied function and the source code location of the log message call site.

◆ errorEnabled()

bool errorEnabled ( ) const
inline

Is error level logging enabled for this logger.

◆ flush()

void flush ( ) const

Flush the streams associated with the logger.

The logger may already be configured to flush after every message.

If the logging system is reconfigured during a call to flush, it is not guaranteed that all or any of the streams will be flushed.

◆ flushAll()

static void flushAll ( )
static

Flush all logging streams.

This call will obtain a lock on the logging mutex.

◆ flushes()

bool flushes ( ) const
inlinenoexcept

Returns true if the logger is auto-flushing.

◆ getConfiguration()

std::string getConfiguration ( ) const

get the logger's configuration as a string (namespace and properties).

This call will obtain a lock on the logging system mutex.

◆ getLevel()

LoggingLevel getLevel ( ) const
inlinenoexcept

Get the logging level of this logger.

◆ getLogger()

static Logger& getLogger ( std::string_view  loggingNamespace)
staticnoexcept

Get a reference to the instance of the logger identified by the supplied namespace.

If the logger instance cannot be obtained, the null logger will be returned and an error message will be logged to stderr.

This call will obtain a lock on the logging system mutex.

Parameters
loggingNamespacethe logger's logging namespace

◆ getNamespace()

std::string getNamespace ( ) const
inline

Get the logging namespace of this logger.

◆ globalLogger()

static Logger& globalLogger ( )
static

A predefined reference to the global logger.

◆ info() [1/10]

void info ( const char *  message) const
inline

Log an info message.

◆ info() [2/10]

void info ( std::string_view  message) const
inline

Log an info message.

◆ info() [3/10]

void info ( const char *  message,
const ObjectT &...  object 
) const
inline

Log an info message with parameters.

◆ info() [4/10]

void info ( std::string_view  message,
const ObjectT &...  object 
) const
inline

Log an info message with parameters.

◆ info() [5/10]

void info ( const std::function< std::string()> &  function) const
inline

Log an info message via the supplied function.

◆ info() [6/10]

void info ( const SourceCodeLocation location,
const char *  message 
) const
inline

Log an info message and the source code location of the log message call site.

◆ info() [7/10]

void info ( const SourceCodeLocation location,
std::string_view  message 
) const
inline

Log an info message and the source code location of the log message call site.

◆ info() [8/10]

void info ( const SourceCodeLocation location,
const char *  message,
const ObjectT &...  object 
) const
inline

Log an info message with parameters and the source code location of the log message call site.

◆ info() [9/10]

void info ( const SourceCodeLocation location,
std::string_view  message,
const ObjectT &...  object 
) const
inline

Log an info message with parameters and the source code location of the log message call site.

◆ info() [10/10]

void info ( const SourceCodeLocation location,
const std::function< std::string()> &  function 
) const
inline

Log an info message via the supplied function and the source code location of the log message call site.

◆ infoEnabled()

bool infoEnabled ( ) const
inline

Is info level logging enabled for this logger.

◆ lockConfiguration()

static void lockConfiguration ( bool  throwOnReconfigure = false)
static

Lock the configuration in order to prevent future reconfiguration.

This call will obtain a lock on the logging system mutex.

Parameters
throwOnReconfiguredetermines whether a subsequent call to the configure method will result in an exception (LoggingConfigurationException) being thrown or whether such a call will be silently ignored.

◆ log() [1/10]

void log ( LoggingLevel  specifiedLevel,
const char *  message 
) const
inline

Log a message.

The error will be logged at the specified level if the level is enabled.

◆ log() [2/10]

void log ( LoggingLevel  specifiedLevel,
std::string_view  message 
) const
inline

Log a message.

The error will be logged at the specified level if the level is enabled.

◆ log() [3/10]

void log ( LoggingLevel  specifiedLevel,
const char *  message,
const ObjectT &...  object 
) const
inline

Log a message with parameters.

The error will be logged at the specified level if the level is enabled.

◆ log() [4/10]

void log ( LoggingLevel  specifiedLevel,
std::string_view  message,
const ObjectT &...  object 
) const
inline

Log a message with parameters.

The error will be logged at the specified level if the level is enabled.

◆ log() [5/10]

void log ( LoggingLevel  specifiedLevel,
const std::function< std::string()> &  function 
) const
inline

Log a error message via the supplied function.

The error will be logged at the specified level if the level is enabled.

◆ log() [6/10]

void log ( LoggingLevel  specifiedLevel,
const SourceCodeLocation location,
const char *  message 
) const
inline

Log an error message and the source code location of the log message call site.

The error will be logged at the specified level if the level is enabled.

◆ log() [7/10]

void log ( LoggingLevel  specifiedLevel,
const SourceCodeLocation location,
std::string_view  message 
) const
inline

Log an error message and the source code location of the log message call site.

The error will be logged at the specified level if the level is enabled.

◆ log() [8/10]

void log ( LoggingLevel  specifiedLevel,
const SourceCodeLocation location,
const char *  message,
const ObjectT &...  object 
) const
inline

Log an error message with parameters and the source code location of the log message call site.

The error will be logged at the specified level if the level is enabled.

◆ log() [9/10]

void log ( LoggingLevel  specifiedLevel,
const SourceCodeLocation location,
std::string_view  message,
const ObjectT &...  object 
) const
inline

Log an error message with parameters and the source code location of the log message call site.

The error will be logged at the specified level if the level is enabled.

◆ log() [10/10]

void log ( LoggingLevel  specifiedLevel,
const SourceCodeLocation location,
const std::function< std::string()> &  function 
) const
inline

Log an error message via the supplied function and the source code location of the log message call site.

The error will be logged at the specified level if the level is enabled.

◆ operator==()

bool operator== ( const Logger logger) const
inline

Compare two loggers for equality.

◆ registerLoggingStreamFactory()

static void registerLoggingStreamFactory ( const std::string &  scheme,
LoggingStreamFactory  factory 
)
static

Register a logging stream factory.

See LoggingStream for information on creating logging stream plugins.

◆ resetConfiguration()

static void resetConfiguration ( )
static

Flush all current logging streams and reconfigure the logging system to the default configuration.

The default configuration will be the default configuration plus the cascade of the configuration obtained from the balau-logging.hconf file if the file exists.

This call will obtain a lock on the logging system mutex.

Exceptions
LoggingConfigurationExceptionif logging reconfiguration has previously been locked.

◆ trace() [1/10]

void trace ( const char *  message) const
inline

Log a trace message.

◆ trace() [2/10]

void trace ( std::string_view  message) const
inline

Log a trace message.

◆ trace() [3/10]

void trace ( const char *  message,
const ObjectT &...  object 
) const
inline

Log a trace message with parameters.

◆ trace() [4/10]

void trace ( std::string_view  message,
const ObjectT &...  object 
) const
inline

Log a trace message with parameters.

◆ trace() [5/10]

void trace ( const std::function< std::string()> &  function) const
inline

Log a trace message via the supplied function.

◆ trace() [6/10]

void trace ( const SourceCodeLocation location,
const char *  message 
) const
inline

Log a trace message and the source code location of the log message call site.

◆ trace() [7/10]

void trace ( const SourceCodeLocation location,
std::string_view  message 
) const
inline

Log a trace message and the source code location of the log message call site.

◆ trace() [8/10]

void trace ( const SourceCodeLocation location,
const char *  message,
const ObjectT &...  object 
) const
inline

Log a trace message with parameters and the source code location of the log message call site.

◆ trace() [9/10]

void trace ( const SourceCodeLocation location,
std::string_view  message,
const ObjectT &...  object 
) const
inline

Log a trace message with parameters and the source code location of the log message call site.

◆ trace() [10/10]

void trace ( const SourceCodeLocation location,
const std::function< std::string()> &  function 
) const
inline

Log a trace message via the supplied function and the source code location of the log message call site.

◆ traceEnabled()

bool traceEnabled ( ) const
inline

Is trace level logging enabled for this logger.

◆ warn() [1/10]

void warn ( const char *  message) const
inline

Log a warn message.

◆ warn() [2/10]

void warn ( std::string_view  message) const
inline

Log a warn message.

◆ warn() [3/10]

void warn ( const char *  message,
const ObjectT &...  object 
) const
inline

Log a warn message with parameters.

◆ warn() [4/10]

void warn ( std::string_view  message,
const ObjectT &...  object 
) const
inline

Log a warn message with parameters.

◆ warn() [5/10]

void warn ( const std::function< std::string()> &  function) const
inline

Log a warn message via the supplied function.

◆ warn() [6/10]

void warn ( const SourceCodeLocation location,
const char *  message 
) const
inline

Log a warn message and the source code location of the log message call site.

◆ warn() [7/10]

void warn ( const SourceCodeLocation location,
std::string_view  message 
) const
inline

Log a warn message and the source code location of the log message call site.

◆ warn() [8/10]

void warn ( const SourceCodeLocation location,
const char *  message,
const ObjectT &...  object 
) const
inline

Log a warn message with parameters and the source code location of the log message call site.

◆ warn() [9/10]

void warn ( const SourceCodeLocation location,
std::string_view  message,
const ObjectT &...  object 
) const
inline

Log a warn message with parameters and the source code location of the log message call site.

◆ warn() [10/10]

void warn ( const SourceCodeLocation location,
const std::function< std::string()> &  function 
) const
inline

Log a warn message via the supplied function and the source code location of the log message call site.

◆ warnEnabled()

bool warnEnabled ( ) const
inline

Is warn level logging enabled for this logger.


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