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>

Public Member Functions

 Logger (const __FlashStringHelper *name, Facility facility=Facility::LOCAL0)
 Create a new logger with the given name and logging facility. 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, 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...
 

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 bool enabled (Level level)
 Determine if the current log level is enabled by any registered handlers. 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 (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 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...
 

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_
 

Static Private Attributes

static Level level_ = Level::OFF
 

Detailed Description

Logger instance used to make log messages.

Since
1.0.0

Definition at line 305 of file log.h.

Constructor & Destructor Documentation

◆ Logger()

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

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 42 of file log.cpp.

Member Function Documentation

◆ alert() [1/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 123 of file log.cpp.

◆ alert() [2/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 133 of file log.cpp.

◆ crit() [1/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 103 of file log.cpp.

◆ crit() [2/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 113 of file log.cpp.

◆ debug() [1/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 222 of file log.cpp.

◆ debug() [2/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 232 of file log.cpp.

◆ dispatch()

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 322 of file log.cpp.

◆ emerg() [1/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 83 of file log.cpp.

◆ emerg() [2/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 93 of file log.cpp.

◆ enabled()

static bool uuid::log::Logger::enabled ( Level  level)
inlinestatic

Determine if the current log level is enabled by any registered handlers.

Returns
The current minimum global log level across all handlers.
Since
1.0.0

Definition at line 372 of file log.h.

◆ err() [1/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 142 of file log.cpp.

◆ err() [2/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 152 of file log.cpp.

◆ 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 71 of file log.cpp.

◆ info() [1/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 202 of file log.cpp.

◆ info() [2/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 212 of file log.cpp.

◆ log() [1/2]

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 262 of file log.cpp.

◆ log() [2/2]

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 278 of file log.cpp.

◆ notice() [1/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 182 of file log.cpp.

◆ notice() [2/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 192 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 333 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 53 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 47 of file log.cpp.

◆ trace() [1/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 242 of file log.cpp.

◆ trace() [2/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 252 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 61 of file log.cpp.

◆ vlog() [1/4]

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

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
1.0.0

Definition at line 294 of file log.cpp.

◆ vlog() [2/4]

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

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
1.0.0

Definition at line 308 of file log.cpp.

◆ vlog() [3/4]

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

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
1.0.0

Definition at line 298 of file log.cpp.

◆ vlog() [4/4]

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

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
1.0.0

Definition at line 312 of file log.cpp.

◆ warning() [1/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 162 of file log.cpp.

◆ warning() [2/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 172 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 619 of file log.h.

◆ level_

Level uuid::log::Logger::level_ = Level::OFF
staticprivate

Minimum global log level across all handlers.

Since
1.0.0

Definition at line 616 of file log.h.

◆ MAX_LOG_LENGTH

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

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 315 of file log.h.

◆ name_

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

Logger name (flash string).

Since
1.0.0

Definition at line 618 of file log.h.


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