My Project
Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
uuid::log::Logger Class Reference

Logger instance used to make log messages. More...

#include <uuid/log.h>

Collaboration diagram for uuid::log::Logger:
Collaboration graph
[legend]

Public Member Functions

 Logger (const __FlashStringHelper *name, Facility facility=Facility::LOCAL0)
 Create a new logger with the given name and logging facility. More...
 
bool enabled (Level level) const
 Determine if the specified log level is enabled by the effective log level. More...
 
Facility facility () const
 Get the default logging facility for new messages of this logger. More...
 
Level level () const
 Get the log level. More...
 
void level (Level level)
 Set the log level. More...
 
Level effective_level () const
 Get the effective log level. More...
 
void emerg (const char *format,...) const
 Log a message at level Level::EMERG. More...
 
void emerg (const __FlashStringHelper *format,...) const
 Log a message at level Level::EMERG. More...
 
void alert (const char *format,...) const
 Log a message at level Level::ALERT. More...
 
void alert (const __FlashStringHelper *format,...) const
 Log a message at level Level::ALERT. More...
 
void crit (const char *format,...) const
 Log a message at level Level::CRIT. More...
 
void crit (const __FlashStringHelper *format,...) const
 Log a message at level Level::CRIT. More...
 
void err (const char *format,...) const
 Log a message at level Level::ERR. More...
 
void err (const __FlashStringHelper *format,...) const
 Log a message at level Level::ERR. More...
 
void warning (const char *format,...) const
 Log a message at level Level::WARNING. More...
 
void warning (const __FlashStringHelper *format,...) const
 Log a message at level Level::WARNING. More...
 
void notice (const char *format,...) const
 Log a message at level Level::NOTICE. More...
 
void notice (const __FlashStringHelper *format,...) const
 Log a message at level Level::NOTICE. More...
 
void info (const char *format,...) const
 Log a message at level Level::INFO. More...
 
void info (const __FlashStringHelper *format,...) const
 Log a message at level Level::INFO. More...
 
void debug (const char *format,...) const
 Log a message at level Level::DEBUG. More...
 
void debug (const __FlashStringHelper *format,...) const
 Log a message at level Level::DEBUG. More...
 
void trace (const char *format,...) const
 Log a message at level Level::TRACE. More...
 
void trace (const __FlashStringHelper *format,...) const
 Log a message at level Level::TRACE. More...
 
void log (Level level, const char *format,...) const
 Log a message with default facility. More...
 
void log (Level level, const __FlashStringHelper *format,...) const
 Log a message with default facility. More...
 
void log (Level level, Facility facility, const char *format,...) const
 Log a message with a custom facility. More...
 
void log (Level level, Facility facility, const __FlashStringHelper *format,...) const
 Log a message with a custom facility. More...
 
void vlog (Level level, const char *format, va_list ap) const
 Log a message at the specified level. More...
 
void vlog (Level level, const __FlashStringHelper *format, va_list ap) const
 Log a message at the specified level. More...
 
void vlog (Level level, Facility facility, const char *format, va_list ap) const
 Log a message at the specified level and facility. More...
 
void vlog (Level level, Facility facility, const __FlashStringHelper *format, va_list ap) const
 Log a message at the specified level and facility. More...
 
void logp (Level level, const char *text) const
 Log a plain message (without formatting) at the specified level. More...
 
void logp (Level level, Facility facility, const char *text) const
 Log an plain message (without formatting) at the specified level and facility. More...
 

Static Public Member Functions

static void register_handler (Handler *handler, Level level)
 Register a log handler. More...
 
static void unregister_handler (Handler *handler)
 Unregister a log handler. More...
 
static Level get_log_level (const Handler *handler)
 Get the current log level of a handler. More...
 
static Level global_level ()
 Get the current global log level. More...
 

Static Public Attributes

static constexpr size_t MAX_LOG_LENGTH = 255
 This is the maximum length of any log message. More...
 

Private Member Functions

void vlog_internal (Level level, Facility facility, const char *format, va_list ap) const
 Log a message at the specified level and facility without checking that the specified level is enabled. More...
 
void vlog_internal (Level level, Facility facility, const __FlashStringHelper *format, va_list ap) const
 Log a message at the specified level and facility without checking that the specified level is enabled. More...
 
void dispatch (Level level, Facility facility, std::vector< char > &text) const
 Dispatch a log message to all handlers that are registered to handle messages of the specified level. More...
 
void dispatch (const std::shared_ptr< Message > &message) const
 Dispatch a log message to all handlers that are registered to handle messages of the specified level. More...
 

Static Private Member Functions

static void refresh_log_level ()
 Refresh the minimum global log level across all handlers. More...
 
static std::shared_ptr< std::map< Handler *, Level > > & registered_handlers ()
 Get registered log handlers. More...
 

Private Attributes

const __FlashStringHelper * name_
 
const Facility facility_
 
Level local_level_ {Level::ALL}
 

Static Private Attributes

static std::atomic< Levelglobal_level_ {Level::OFF}
 
static std::mutex mutex_
 

Detailed Description

Logger instance used to make log messages.

Since
1.0.0

Definition at line 347 of file log.h.

Constructor & Destructor Documentation

◆ Logger()

uuid::log::Logger::Logger ( const __FlashStringHelper *  name,
Facility  facility = Facility::LOCAL0 
)
explicit

Create a new logger with the given name and logging facility.

Parameters
[in]nameLogger name (flash string).
[in]facilityDefault logging facility for messages.
Since
1.0.0

Definition at line 60 of file log.cpp.

Member Function Documentation

◆ alert() [1/2]

void uuid::log::Logger::alert ( const __FlashStringHelper *  format,
  ... 
) const

Log a message at level Level::ALERT.

Parameters
[in]formatFormat string (flash string).
[in]...Format string arguments.
Since
1.0.0

Definition at line 161 of file log.cpp.

◆ alert() [2/2]

void uuid::log::Logger::alert ( const char *  format,
  ... 
) const

Log a message at level Level::ALERT.

Parameters
[in]formatFormat string.
[in]...Format string arguments.
Since
1.0.0

Definition at line 151 of file log.cpp.

◆ crit() [1/2]

void uuid::log::Logger::crit ( const __FlashStringHelper *  format,
  ... 
) const

Log a message at level Level::CRIT.

Parameters
[in]formatFormat string (flash string).
[in]...Format string arguments.
Since
1.0.0

Definition at line 141 of file log.cpp.

◆ crit() [2/2]

void uuid::log::Logger::crit ( const char *  format,
  ... 
) const

Log a message at level Level::CRIT.

Parameters
[in]formatFormat string.
[in]...Format string arguments.
Since
1.0.0

Definition at line 131 of file log.cpp.

◆ debug() [1/2]

void uuid::log::Logger::debug ( const __FlashStringHelper *  format,
  ... 
) const

Log a message at level Level::DEBUG.

Parameters
[in]formatFormat string (flash string).
[in]...Format string arguments.
Since
1.0.0

Definition at line 260 of file log.cpp.

◆ debug() [2/2]

void uuid::log::Logger::debug ( const char *  format,
  ... 
) const

Log a message at level Level::DEBUG.

Parameters
[in]formatFormat string.
[in]...Format string arguments.
Since
1.0.0

Definition at line 250 of file log.cpp.

◆ dispatch() [1/2]

void uuid::log::Logger::dispatch ( const std::shared_ptr< Message > &  message) const
inlineprivate

Dispatch a log message to all handlers that are registered to handle messages of the specified level.

Parameters
[in]messageLog message.
Since
3.1.0

Definition at line 410 of file log.cpp.

◆ dispatch() [2/2]

void uuid::log::Logger::dispatch ( Level  level,
Facility  facility,
std::vector< char > &  text 
) const
private

Dispatch a log message to all handlers that are registered to handle messages of the specified level.

Automatically sets the timestamp of the message to the current system uptime.

Parameters
[in]levelSeverity level of the message.
[in]facilityFacility type of the process logging the message.
[in]textLog message text.
Since
1.0.0

Definition at line 403 of file log.cpp.

◆ effective_level()

Level uuid::log::Logger::effective_level ( ) const
inline

Get the effective log level.

Returns
The effective log level for this logger.
Since
3.0.0

Definition at line 458 of file log.h.

◆ emerg() [1/2]

void uuid::log::Logger::emerg ( const __FlashStringHelper *  format,
  ... 
) const

Log a message at level Level::EMERG.

Parameters
[in]formatFormat string (flash string).
[in]...Format string arguments.
Since
1.0.0

Definition at line 121 of file log.cpp.

◆ emerg() [2/2]

void uuid::log::Logger::emerg ( const char *  format,
  ... 
) const

Log a message at level Level::EMERG.

Parameters
[in]formatFormat string.
[in]...Format string arguments.
Since
1.0.0

Definition at line 111 of file log.cpp.

◆ enabled()

bool uuid::log::Logger::enabled ( Level  level) const
inline

Determine if the specified log level is enabled by the effective log level.

Parameters
[in]levelLog level to check.
Returns
If the specified log level is enabled on this logger.
Since
3.0.0

Definition at line 422 of file log.h.

◆ err() [1/2]

void uuid::log::Logger::err ( const __FlashStringHelper *  format,
  ... 
) const

Log a message at level Level::ERR.

Parameters
[in]formatFormat string (flash string).
[in]...Format string arguments.
Since
1.0.0

Definition at line 180 of file log.cpp.

◆ err() [2/2]

void uuid::log::Logger::err ( const char *  format,
  ... 
) const

Log a message at level Level::ERR.

Parameters
[in]formatFormat string.
[in]...Format string arguments.
Since
1.0.0

Definition at line 170 of file log.cpp.

◆ facility()

Facility uuid::log::Logger::facility ( ) const
inline

Get the default logging facility for new messages of this logger.

Returns
The default logging facility for messages.
Since
2.3.0

Definition at line 430 of file log.h.

◆ get_log_level()

Level uuid::log::Logger::get_log_level ( const Handler handler)
static

Get the current log level of a handler.

It is safe to call this with a handler that is not registered.

Parameters
[in]handlerHandler object that may handle log messages.
Returns
The current log level of the specified handler.
Since
1.0.0

Definition at line 96 of file log.cpp.

◆ global_level()

static Level uuid::log::Logger::global_level ( )
inlinestatic

Get the current global log level.

Returns
The minimum log level across all handlers.
Since
3.0.0

Definition at line 412 of file log.h.

◆ info() [1/2]

void uuid::log::Logger::info ( const __FlashStringHelper *  format,
  ... 
) const

Log a message at level Level::INFO.

Parameters
[in]formatFormat string (flash string).
[in]...Format string arguments.

Definition at line 240 of file log.cpp.

◆ info() [2/2]

void uuid::log::Logger::info ( const char *  format,
  ... 
) const

Log a message at level Level::INFO.

Parameters
[in]formatFormat string.
[in]...Format string arguments.
Since
1.0.0

Definition at line 230 of file log.cpp.

◆ level() [1/2]

Level uuid::log::Logger::level ( ) const
inline

Get the log level.

The effective log level will be depend on handlers.

Returns
The log level of this logger.
Since
3.0.0

Definition at line 440 of file log.h.

◆ level() [2/2]

void uuid::log::Logger::level ( Level  level)
inline

Set the log level.

The effective log level will be depend on handlers.

Parameters
[in]levelLog level for this logger.
Since
3.0.0

Definition at line 450 of file log.h.

◆ log() [1/4]

void uuid::log::Logger::log ( Level  level,
const __FlashStringHelper *  format,
  ... 
) const

Log a message with default facility.

Parameters
[in]levelSeverity level of the message.
[in]formatFormat string (flash string).
[in]...Format string arguments.
Since
3.0.0

Definition at line 302 of file log.cpp.

◆ log() [2/4]

void uuid::log::Logger::log ( Level  level,
const char *  format,
  ... 
) const

Log a message with default facility.

Parameters
[in]levelSeverity level of the message.
[in]formatFormat string.
[in]...Format string arguments.
Since
3.0.0

Definition at line 290 of file log.cpp.

◆ log() [3/4]

void uuid::log::Logger::log ( Level  level,
Facility  facility,
const __FlashStringHelper *  format,
  ... 
) const

Log a message with a custom facility.

Parameters
[in]levelSeverity level of the message.
[in]facilityFacility type of the process logging the message.
[in]formatFormat string (flash string).
[in]...Format string arguments.
Since
1.0.0

Definition at line 326 of file log.cpp.

◆ log() [4/4]

void uuid::log::Logger::log ( Level  level,
Facility  facility,
const char *  format,
  ... 
) const

Log a message with a custom facility.

Parameters
[in]levelSeverity level of the message.
[in]facilityFacility type of the process logging the message.
[in]formatFormat string.
[in]...Format string arguments.
Since
1.0.0

Definition at line 314 of file log.cpp.

◆ logp() [1/2]

void uuid::log::Logger::logp ( Level  level,
const char *  text 
) const

Log a plain message (without formatting) at the specified level.

Parameters
[in]levelSeverity level of the message.
[in]textText for the message.
Since
3.1.0

Definition at line 390 of file log.cpp.

◆ logp() [2/2]

void uuid::log::Logger::logp ( Level  level,
Facility  facility,
const char *  text 
) const

Log an plain message (without formatting) at the specified level and facility.

Parameters
[in]levelSeverity level of the message.
[in]facilityFacility type of the process logging the message.
[in]textText for the message.
Since
3.1.0

Definition at line 394 of file log.cpp.

◆ notice() [1/2]

void uuid::log::Logger::notice ( const __FlashStringHelper *  format,
  ... 
) const

Log a message at level Level::NOTICE.

Parameters
[in]formatFormat string (flash string).
[in]...Format string arguments.
Since
1.0.0

Definition at line 220 of file log.cpp.

◆ notice() [2/2]

void uuid::log::Logger::notice ( const char *  format,
  ... 
) const

Log a message at level Level::NOTICE.

Parameters
[in]formatFormat string.
[in]...Format string arguments.
Since
1.0.0

Definition at line 210 of file log.cpp.

◆ refresh_log_level()

void uuid::log::Logger::refresh_log_level ( )
staticprivate

Refresh the minimum global log level across all handlers.

Since
1.0.0

Definition at line 423 of file log.cpp.

◆ register_handler()

void uuid::log::Logger::register_handler ( Handler handler,
Level  level 
)
static

Register a log handler.

Call again to change the log level.

Parameters
[in]handlerHandler object that will handle log messages.
[in]levelMinimum log level that the handler is interested in.
Since
1.0.0

Definition at line 71 of file log.cpp.

◆ registered_handlers()

std::shared_ptr< std::map< Handler *, Level > > & uuid::log::Logger::registered_handlers ( )
staticprivate

Get registered log handlers.

Returns
The registered log handlers.
Since
2.1.2

Definition at line 65 of file log.cpp.

◆ trace() [1/2]

void uuid::log::Logger::trace ( const __FlashStringHelper *  format,
  ... 
) const

Log a message at level Level::TRACE.

Parameters
[in]formatFormat string (flash string).
[in]...Format string arguments.
Since
1.0.0

Definition at line 280 of file log.cpp.

◆ trace() [2/2]

void uuid::log::Logger::trace ( const char *  format,
  ... 
) const

Log a message at level Level::TRACE.

Parameters
[in]formatFormat string.
[in]...Format string arguments.
Since
1.0.0

Definition at line 270 of file log.cpp.

◆ unregister_handler()

void uuid::log::Logger::unregister_handler ( Handler handler)
static

Unregister a log handler.

It is safe to call this with a handler that is not registered.

Parameters
[in]handlerHandler object that will no longer handle log messages.
Since
1.0.0

Definition at line 82 of file log.cpp.

◆ vlog() [1/4]

void uuid::log::Logger::vlog ( Level  level,
const __FlashStringHelper *  format,
va_list  ap 
) const

Log a message at the specified level.

Parameters
[in]levelSeverity level of the message.
[in]formatFormat string (flash string).
[in]apVariable arguments pointer for format string.
Since
3.1.0

Definition at line 354 of file log.cpp.

◆ vlog() [2/4]

void uuid::log::Logger::vlog ( Level  level,
const char *  format,
va_list  ap 
) const

Log a message at the specified level.

Parameters
[in]levelSeverity level of the message.
[in]formatFormat string.
[in]apVariable arguments pointer for format string.
Since
3.1.0

Definition at line 338 of file log.cpp.

◆ vlog() [3/4]

void uuid::log::Logger::vlog ( Level  level,
Facility  facility,
const __FlashStringHelper *  format,
va_list  ap 
) const

Log a message at the specified level and facility.

Parameters
[in]levelSeverity level of the message.
[in]facilityFacility type of the process logging the message.
[in]formatFormat string (flash string).
[in]apVariable arguments pointer for format string.
Since
3.1.0

Definition at line 362 of file log.cpp.

◆ vlog() [4/4]

void uuid::log::Logger::vlog ( Level  level,
Facility  facility,
const char *  format,
va_list  ap 
) const

Log a message at the specified level and facility.

Parameters
[in]levelSeverity level of the message.
[in]facilityFacility type of the process logging the message.
[in]formatFormat string.
[in]apVariable arguments pointer for format string.
Since
3.1.0

Definition at line 346 of file log.cpp.

◆ vlog_internal() [1/2]

void uuid::log::Logger::vlog_internal ( Level  level,
Facility  facility,
const __FlashStringHelper *  format,
va_list  ap 
) const
private

Log a message at the specified level and facility without checking that the specified level is enabled.

Parameters
[in]levelSeverity level of the message.
[in]facilityFacility type of the process logging the message.
[in]formatFormat string (flash string).
[in]apVariable arguments pointer for format string.
Since
3.1.0

Definition at line 380 of file log.cpp.

◆ vlog_internal() [2/2]

void uuid::log::Logger::vlog_internal ( Level  level,
Facility  facility,
const char *  format,
va_list  ap 
) const
private

Log a message at the specified level and facility without checking that the specified level is enabled.

Parameters
[in]levelSeverity level of the message.
[in]facilityFacility type of the process logging the message.
[in]formatFormat string.
[in]apVariable arguments pointer for format string.
Since
3.1.0

Definition at line 370 of file log.cpp.

◆ warning() [1/2]

void uuid::log::Logger::warning ( const __FlashStringHelper *  format,
  ... 
) const

Log a message at level Level::WARNING.

Parameters
[in]formatFormat string (flash string).
[in]...Format string arguments.
Since
1.0.0

Definition at line 200 of file log.cpp.

◆ warning() [2/2]

void uuid::log::Logger::warning ( const char *  format,
  ... 
) const

Log a message at level Level::WARNING.

Parameters
[in]formatFormat string.
[in]...Format string arguments.
Since
1.0.0

Definition at line 190 of file log.cpp.

Member Data Documentation

◆ facility_

const Facility uuid::log::Logger::facility_
private

Default logging facility for messages.

Since
1.0.0

Definition at line 778 of file log.h.

◆ global_level_

std::atomic< Level > uuid::log::Logger::global_level_ {Level::OFF}
staticprivate

Minimum global log level across all handlers.

Since
3.0.0

Definition at line 772 of file log.h.

◆ local_level_

Level uuid::log::Logger::local_level_ {Level::ALL}
private

Logger level.

Since
3.0.0

Definition at line 779 of file log.h.

◆ MAX_LOG_LENGTH

constexpr size_t uuid::log::Logger::MAX_LOG_LENGTH = 255
staticconstexpr

This is the maximum length of any log message.

Determines the size of the buffer used for format string printing.

Since
1.0.0

Definition at line 357 of file log.h.

◆ mutex_

std::mutex uuid::log::Logger::mutex_
staticprivate

Mutex for handlers.

Since
2.3.0

Definition at line 774 of file log.h.

◆ name_

const __FlashStringHelper* uuid::log::Logger::name_
private

Logger name (flash string).

Since
1.0.0

Definition at line 777 of file log.h.


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