Embedded Artistry Framework
Embedded Systems C++ Framework
Namespaces | Classes | Macros
Logging Subsystem

Subsystem which provides logging support. More...

Collaboration diagram for Logging Subsystem:

Namespaces

 embvm::logger
 Log definitions.
 

Classes

class  embvm::CircularLogBufferLogger< TBufferSize, TLock >
 Circular log buffer. More...
 
class  embvm::LoggerBase< TLock >
 Base class for logger implementations. More...
 
class  embvm::PlatformLogger_t< TLogger >
 Declare a static platform logger instance. More...
 

Macros

#define LOG_LEVEL   LOG_LEVEL_DEBUG
 Default maximum log level. More...
 
#define LOG_EN_DEFAULT   true
 Whether the logging module is enabled automatically on boot. More...
 
#define LOG_ECHO_EN_DEFAULT   false
 Indicates that log statements should be echoed to the console If true, log statements will be echoed. More...
 
#define LOG_LEVEL_NAMES
 Users can override these default names with a compiler definition. More...
 
#define LOG_LEVEL_SHORT_NAMES
 Users can override these default short names with a compiler definition. More...
 

Log Level Definitions

#define LOG_LEVEL_OFF   0
 Logging is disabled. More...
 
#define LOG_LEVEL_CRITICAL   1
 Indicates the system is unusable, or an error that is unrecoverable. More...
 
#define LOG_LEVEL_ERROR   2
 Indicates an error condition. More...
 
#define LOG_LEVEL_WARN   3
 Indicates a warning condition. More...
 
#define LOG_LEVEL_INFO   4
 Informational messages. More...
 
#define LOG_LEVEL_DEBUG   5
 Debug-level messages. More...
 
#define LOG_LEVEL_VERBOSE   6
 Extra super verbose messages. More...
 
#define LOG_LEVEL_MAX   LOG_LEVEL_VERBOSE
 The maximum log level that can be set. More...
 
#define LOG_LEVEL_COUNT   (LOG_LEVEL_MAX + 1)
 The number of possible log levels. More...
 

Log Level Prefixes

#define LOG_LEVEL_CRITICAL_PREFIX   "!"
 
#define LOG_LEVEL_ERROR_PREFIX   "E"
 
#define LOG_LEVEL_WARNING_PREFIX   "W"
 
#define LOG_LEVEL_INFO_PREFIX   "I"
 
#define LOG_LEVEL_DEBUG_PREFIX   "D"
 
#define LOG_LEVEL_VERBOSE_PREFIX   "V"
 
#define LOG_LEVEL_INTERRUPT_PREFIX   "I"
 

Logging Macros

The log macros can be overridden by defining them in your platform_logger.hpp file

For more information see docs/development/ExtendingTheFramework/customizing_log_macros.md

#define logcritical(...)   PlatformLogger::inst().log(embvm::logger::level::critical, __VA_ARGS__)
 
#define logerror(...)   PlatformLogger::inst().log(embvm::logger::level::error, __VA_ARGS__)
 
#define logwarn(...)   PlatformLogger::inst().log(embvm::logger::level::warn, __VA_ARGS__)
 
#define loginfo(...)   PlatformLogger::inst().log(embvm::logger::level::info, __VA_ARGS__)
 
#define logdebug(...)   PlatformLogger::inst().log(embvm::logger::level::debug, __VA_ARGS__)
 
#define logverbose(...)   PlatformLogger::inst().log(embvm::logger::level::verbose, __VA_ARGS__)
 

Detailed Description

Subsystem which provides logging support.


Class Documentation

◆ embvm::CircularLogBufferLogger

class embvm::CircularLogBufferLogger

template<size_t TBufferSize = (8 * 1024), typename TLock = embutil::nop_lock>
class embvm::CircularLogBufferLogger< TBufferSize, TLock >

Circular log buffer.

A circular log buffer manages a memoroy buffer as if it were neverending. When the capacity of the buffer is reached, insertions will wrap around to the beginning of the buffer and overwrite old data. This enables seemingly "infinite" memory with a fixed capacity, preferring the newest data be kept.

Template Parameters
TBufferSizeDefines the size of the circular log buffer. Set to 0 to disable logging completely (for memory constrained systems).
Note
Size requirement: power-of-2 for optimized queue logic.
Template Parameters
TLockthe type of lock to use with the LoggerBase. Locking is disabled by default (with the use of embutil::nop_lock). You can enable locking by declaring this class with a functional lock type.
Inheritance diagram for embvm::CircularLogBufferLogger< TBufferSize, TLock >:
Inheritance graph

Public Member Functions

 CircularLogBufferLogger ()
 Default constructor. More...
 
 CircularLogBufferLogger (embvm::clk::SystemClock &clk) noexcept
 Initialize the circular log buffer with a system clock for timestamp support. More...
 
 CircularLogBufferLogger (bool enable, logger::level l=logger::LOG_LEVEL_LIMIT, bool echo=LOG_ECHO_EN_DEFAULT) noexcept
 Initialize the circular log buffer with options. More...
 
 CircularLogBufferLogger (embvm::clk::SystemClock &clk, bool enable, logger::level l=logger::LOG_LEVEL_LIMIT, bool echo=LOG_ECHO_EN_DEFAULT) noexcept
 Initialize the circular log buffer with options and a system clock for timestamp support. More...
 
 ~CircularLogBufferLogger () noexcept=default
 Default destructor. More...
 
size_t size () const noexcept final
 Get the current log buffer size. More...
 
size_t capacity () const noexcept final
 Get the log buffer capacity. More...
 
void dump () noexcept final
 Print the contents of the log buffer in the console. More...
 
void clear () noexcept final
 Clear the contents of the log buffer. More...
 
bool enabled () const noexcept
 Check if the log is enabled. More...
 
bool enabled (bool en) noexcept
 Enable/disable logging. More...
 
bool echo () const noexcept
 Check the echo setting. More...
 
bool echo (bool en) noexcept
 Enable/disable echo to console. More...
 
logger::level level () const noexcept
 Get the maximum log level (filtering) More...
 
logger::level level (logger::level l) noexcept
 Set the maximum log level (filtering) More...
 
template<typename... Args>
void log (logger::level l, const char *fmt, const Args &... args) noexcept
 Add data to the log buffer. More...
 
void setClock (embvm::clk::SystemClock &clk) noexcept
 Set the system clock. More...
 

Protected Member Functions

void log_putc (char c) noexcept final
 Log buffer putc function. More...
 

Static Protected Member Functions

static void log_putc_bounce (char c, void *this_ptr)
 putc bounce function More...
 

Private Attributes

char buffer_ [TBufferSize] = {0}
 
stdext::ring_span< char > log_buffer_ {buffer_, buffer_ + TBufferSize}
 

Constructor & Destructor Documentation

◆ CircularLogBufferLogger() [1/4]

template<size_t TBufferSize = (8 * 1024), typename TLock = embutil::nop_lock>
embvm::CircularLogBufferLogger< TBufferSize, TLock >::CircularLogBufferLogger ( )
inline

Default constructor.

◆ CircularLogBufferLogger() [2/4]

template<size_t TBufferSize = (8 * 1024), typename TLock = embutil::nop_lock>
embvm::CircularLogBufferLogger< TBufferSize, TLock >::CircularLogBufferLogger ( embvm::clk::SystemClock clk)
inlineexplicitnoexcept

Initialize the circular log buffer with a system clock for timestamp support.

If a system clock instance is provided to the logger, timestamps will be appended to each log statement.

Parameters
clkThe system clock instance to use for timestamping.

◆ CircularLogBufferLogger() [3/4]

template<size_t TBufferSize = (8 * 1024), typename TLock = embutil::nop_lock>
embvm::CircularLogBufferLogger< TBufferSize, TLock >::CircularLogBufferLogger ( bool  enable,
logger::level  l = logger::LOG_LEVEL_LIMIT,
bool  echo = LOG_ECHO_EN_DEFAULT 
)
inlineexplicitnoexcept

Initialize the circular log buffer with options.

Parameters
enableIf true, log statements will be output to the log buffer. If false, logging will be disabled and log statements will not be output to the log buffer.
lRuntime log filtering level. Levels greater than the target will not be output to the log buffer.
echoIf true, log statements will be logged and printed to the console with printf(). If false, log statements will only be added to the log buffer.

◆ CircularLogBufferLogger() [4/4]

template<size_t TBufferSize = (8 * 1024), typename TLock = embutil::nop_lock>
embvm::CircularLogBufferLogger< TBufferSize, TLock >::CircularLogBufferLogger ( embvm::clk::SystemClock clk,
bool  enable,
logger::level  l = logger::LOG_LEVEL_LIMIT,
bool  echo = LOG_ECHO_EN_DEFAULT 
)
inlineexplicitnoexcept

Initialize the circular log buffer with options and a system clock for timestamp support.

If a system clock instance is provided to the logger, timestamps will be appended to each log statement.

Parameters
clkThe system clock instance to use for timestamping.
enableIf true, log statements will be output to the log buffer. If false, logging will be disabled and log statements will not be output to the log buffer.
lRuntime log filtering level. Levels greater than the target will not be output to the log buffer.
echoIf true, log statements will be logged and printed to the console with printf(). If false, log statements will only be added to the log buffer.

◆ ~CircularLogBufferLogger()

template<size_t TBufferSize = (8 * 1024), typename TLock = embutil::nop_lock>
embvm::CircularLogBufferLogger< TBufferSize, TLock >::~CircularLogBufferLogger ( )
defaultnoexcept

Default destructor.

Member Function Documentation

◆ capacity()

template<size_t TBufferSize = (8 * 1024), typename TLock = embutil::nop_lock>
size_t embvm::CircularLogBufferLogger< TBufferSize, TLock >::capacity ( ) const
inlinefinalvirtualnoexcept

Get the log buffer capacity.

Derived classes must implement this function.

Returns
The total capacity of the log buffer, in bytes.

Implements embvm::LoggerBase< TLock >.

References embvm::CircularLogBufferLogger< TBufferSize, TLock >::log_buffer_.

◆ clear()

template<size_t TBufferSize = (8 * 1024), typename TLock = embutil::nop_lock>
void embvm::CircularLogBufferLogger< TBufferSize, TLock >::clear ( )
inlinefinalvirtualnoexcept

Clear the contents of the log buffer.

Reset the log buffer to an empty state.

Postcondition
The log buffer will be empty.

Implements embvm::LoggerBase< TLock >.

References embvm::CircularLogBufferLogger< TBufferSize, TLock >::log_buffer_.

◆ dump()

template<size_t TBufferSize = (8 * 1024), typename TLock = embutil::nop_lock>
void embvm::CircularLogBufferLogger< TBufferSize, TLock >::dump ( )
inlinefinalvirtualnoexcept

Print the contents of the log buffer in the console.

When called, the contents of the log buffer will be echo'd to the console through printf. The entire log buffer will be displayed.

Derived classes must implement this function.

Implements embvm::LoggerBase< TLock >.

References _putchar(), embvm::CircularLogBufferLogger< TBufferSize, TLock >::log_buffer_, and t.

◆ echo() [1/2]

template<typename TLock >
bool embvm::LoggerBase< TLock >::echo ( ) const
inlinenoexceptinherited

Check the echo setting.

Returns
true if echo to console is enabled, false if disabled.

References embvm::LoggerBase< TLock >::echo_.

◆ echo() [2/2]

template<typename TLock >
bool embvm::LoggerBase< TLock >::echo ( bool  en)
inlinenoexceptinherited

Enable/disable echo to console.

Parameters
enEcho switch. If true, log statements will also be echo'd to the console through printf(). If false, log statements will only go to the log buffer.
Returns
true if echo to console is enabled, false if disabled.

References embvm::LoggerBase< TLock >::echo_.

◆ enabled() [1/2]

template<typename TLock >
bool embvm::LoggerBase< TLock >::enabled ( ) const
inlinenoexceptinherited

Check if the log is enabled.

Returns
true if log output is enabled, false if it is disabled.

References embvm::LoggerBase< TLock >::enabled_.

◆ enabled() [2/2]

template<typename TLock >
bool embvm::LoggerBase< TLock >::enabled ( bool  en)
inlinenoexceptinherited

Enable/disable logging.

Parameters
enEnable switch. If true, logging is enabled. If false, logging is disabled.
Returns
true if log output is enabled, false if it is disabled.

References embvm::LoggerBase< TLock >::enabled_.

◆ level() [1/2]

template<typename TLock >
logger::level embvm::LoggerBase< TLock >::level ( ) const
inlinenoexceptinherited

Get the maximum log level (filtering)

Returns
the current log level maximum.

References embvm::LoggerBase< TLock >::level_.

◆ level() [2/2]

template<typename TLock >
logger::level embvm::LoggerBase< TLock >::level ( logger::level  l)
inlinenoexceptinherited

Set the maximum log level (filtering)

Parameters
lThe maximum log level. Levels grater than l will not be added to the log buffer.
Returns
the current log level maximum.

References embvm::LoggerBase< TLock >::level_, and embvm::logger::LOG_LEVEL_LIMIT.

◆ log()

template<typename TLock >
template<typename... Args>
void embvm::LoggerBase< TLock >::log ( logger::level  l,
const char *  fmt,
const Args &...  args 
)
inlinenoexceptinherited

Add data to the log buffer.

Template Parameters
ArgsVariadic template args. Will be deduced by the compiler. Enables support for a variadic function template.
Parameters
lThe log level associated with this statement.
fmtThe log format string.
argsThe variadic arguments that are associated with the format string.

References embvm::LoggerBase< TLock >::echo_, embvm::LoggerBase< TLock >::enabled_, fctprintf(), embvm::LoggerBase< TLock >::level_, embvm::LoggerBase< TLock >::log_putc_bounce(), embvm::LoggerBase< TLock >::mutex_, printf, embvm::LoggerBase< TLock >::system_clock_, embvm::clk::SystemClock::ticks(), and embvm::logger::to_short_c_str().

◆ log_putc()

template<size_t TBufferSize = (8 * 1024), typename TLock = embutil::nop_lock>
void embvm::CircularLogBufferLogger< TBufferSize, TLock >::log_putc ( char  c)
inlinefinalprotectedvirtualnoexcept

Log buffer putc function.

This function adds a character to the underlying log buffer.

This function is used with the fctprintf() interface to output to the log buffer. This enables the framework to reuse the same print formatting for both logging and printf().

Derived classes must implement this function.

Parameters
cThe character to insert into the log buffer.

Implements embvm::LoggerBase< TLock >.

References embvm::CircularLogBufferLogger< TBufferSize, TLock >::log_buffer_.

◆ log_putc_bounce()

template<typename TLock >
static void embvm::LoggerBase< TLock >::log_putc_bounce ( char  c,
void *  this_ptr 
)
inlinestaticprotectedinherited

putc bounce function

This is a bounce function which registers with the C printf API. We use the private parameter to store the this pointer so we can get back to our logger's putc instance.

Parameters
cThe character to log.
this_ptrThe this pointer of the logger instance. Used to invoke log_putc() on the correct instance.

Referenced by embvm::LoggerBase< TLock >::log().

◆ setClock()

template<typename TLock >
void embvm::LoggerBase< TLock >::setClock ( embvm::clk::SystemClock clk)
inlinenoexceptinherited

Set the system clock.

Parameters
clkThe system clock instance to use for timestamping.

References embvm::LoggerBase< TLock >::system_clock_.

◆ size()

template<size_t TBufferSize = (8 * 1024), typename TLock = embutil::nop_lock>
size_t embvm::CircularLogBufferLogger< TBufferSize, TLock >::size ( ) const
inlinefinalvirtualnoexcept

Get the current log buffer size.

Derived classes must implement this function.

Returns
The current size of the log buffer, in bytes.

Implements embvm::LoggerBase< TLock >.

References embvm::CircularLogBufferLogger< TBufferSize, TLock >::log_buffer_.

Member Data Documentation

◆ buffer_

template<size_t TBufferSize = (8 * 1024), typename TLock = embutil::nop_lock>
char embvm::CircularLogBufferLogger< TBufferSize, TLock >::buffer_[TBufferSize] = {0}
private

◆ log_buffer_

◆ embvm::LoggerBase

class embvm::LoggerBase

template<typename TLock>
class embvm::LoggerBase< TLock >

Base class for logger implementations.

This class provides the interface for loggers, as well as implements basic operations. To create a logger, you can derive from this class and fill in the missing operations.

For an example logger implementation, see the CircularLogBufferLogger in circular_buffer_logger.hpp.

Using a Logger

The primary method for interacting with a logger is through the log() interface. Macros are provided for convenient logging at different levels (loginfo(), logdebug(), logerror(), etc).

The full contents of the log buffer can be dumped to the console using the dump() API.

Defining a Logger

Do declare your own logger type, inherit from this base class:

class CircularLogBufferLogger final : public LoggerBase

This derived class is used to declare the actual log bufer storage and handle the log buffer implementation.

Derived classes must implement the following functions to control specific log behavior:

Template Parameters
TLockthe type of lock to use with the LoggerBase. Locking can be disabled by using the embutil::nop_lock type.
Inheritance diagram for embvm::LoggerBase< TLock >:
Inheritance graph

Public Member Functions

virtual size_t size () const noexcept=0
 Get the current log buffer size. More...
 
virtual size_t capacity () const noexcept=0
 Get the log buffer capacity. More...
 
bool enabled () const noexcept
 Check if the log is enabled. More...
 
bool enabled (bool en) noexcept
 Enable/disable logging. More...
 
bool echo () const noexcept
 Check the echo setting. More...
 
bool echo (bool en) noexcept
 Enable/disable echo to console. More...
 
logger::level level () const noexcept
 Get the maximum log level (filtering) More...
 
logger::level level (logger::level l) noexcept
 Set the maximum log level (filtering) More...
 
template<typename... Args>
void log (logger::level l, const char *fmt, const Args &... args) noexcept
 Add data to the log buffer. More...
 
void setClock (embvm::clk::SystemClock &clk) noexcept
 Set the system clock. More...
 
virtual void dump () noexcept=0
 Print the contents of the log buffer in the console. More...
 
virtual void clear () noexcept=0
 Clear the contents of the log buffer. More...
 

Protected Member Functions

 LoggerBase ()=default
 Default constructor. More...
 
 LoggerBase (embvm::clk::SystemClock &clk) noexcept
 Initialize the logger with a system clock for timestamp support. More...
 
 LoggerBase (bool enable, logger::level l=logger::LOG_LEVEL_LIMIT, bool echo=LOG_ECHO_EN_DEFAULT) noexcept
 Initialize the logger with options. More...
 
 LoggerBase (embvm::clk::SystemClock &clk, bool enable, logger::level l=logger::LOG_LEVEL_LIMIT, bool echo=LOG_ECHO_EN_DEFAULT)
 Initialize the logger with options and a system clock for timestamp support. More...
 
virtual ~LoggerBase ()=default
 Default destructor. More...
 
virtual void log_putc (char c)=0
 Log buffer putc function. More...
 

Static Protected Member Functions

static void log_putc_bounce (char c, void *this_ptr)
 putc bounce function More...
 

Private Attributes

bool enabled_ = LOG_EN_DEFAULT
 Indicates whether logging is currently enabled. More...
 
logger::level level_ = logger::LOG_LEVEL_LIMIT
 The current log level. More...
 
bool echo_ = LOG_ECHO_EN_DEFAULT
 Console echoing. More...
 
TLock mutex_
 Mutex which protects the log buffer. More...
 
embvm::clk::SystemClocksystem_clock_ = nullptr
 The system clock instance, used for timestamping. More...
 

Constructor & Destructor Documentation

◆ LoggerBase() [1/4]

template<typename TLock >
embvm::LoggerBase< TLock >::LoggerBase ( )
protecteddefault

Default constructor.

◆ LoggerBase() [2/4]

template<typename TLock >
embvm::LoggerBase< TLock >::LoggerBase ( embvm::clk::SystemClock clk)
inlineexplicitprotectednoexcept

Initialize the logger with a system clock for timestamp support.

If a system clock instance is provided to the logger, timestamps will be appended to each log statement.

Parameters
clkThe system clock instance to use for timestamping.

◆ LoggerBase() [3/4]

template<typename TLock >
embvm::LoggerBase< TLock >::LoggerBase ( bool  enable,
logger::level  l = logger::LOG_LEVEL_LIMIT,
bool  echo = LOG_ECHO_EN_DEFAULT 
)
inlineexplicitprotectednoexcept

Initialize the logger with options.

Parameters
enableIf true, log statements will be output to the log buffer. If false, logging will be disabled and log statements will not be output to the log buffer.
lRuntime log filtering level. Levels greater than the target will not be output to the log buffer.
echoIf true, log statements will be logged and printed to the console with printf(). If false, log statements will only be added to the log buffer.

◆ LoggerBase() [4/4]

template<typename TLock >
embvm::LoggerBase< TLock >::LoggerBase ( embvm::clk::SystemClock clk,
bool  enable,
logger::level  l = logger::LOG_LEVEL_LIMIT,
bool  echo = LOG_ECHO_EN_DEFAULT 
)
inlineexplicitprotected

Initialize the logger with options and a system clock for timestamp support.

If a system clock instance is provided to the logger, timestamps will be appended to each log statement.

Parameters
clkThe system clock instance to use for timestamping.
enableIf true, log statements will be output to the log buffer. If false, logging will be disabled and log statements will not be output to the log buffer.
lRuntime log filtering level. Levels greater than the target will not be output to the log buffer.
echoIf true, log statements will be logged and printed to the console with printf(). If false, log statements will only be added to the log buffer.

◆ ~LoggerBase()

template<typename TLock >
virtual embvm::LoggerBase< TLock >::~LoggerBase ( )
protectedvirtualdefault

Default destructor.

Member Function Documentation

◆ capacity()

template<typename TLock >
virtual size_t embvm::LoggerBase< TLock >::capacity ( ) const
pure virtualnoexcept

Get the log buffer capacity.

Derived classes must implement this function.

Returns
The total capacity of the log buffer, in bytes.

Implemented in embvm::CircularLogBufferLogger< TBufferSize, TLock >.

◆ clear()

template<typename TLock >
virtual void embvm::LoggerBase< TLock >::clear ( )
pure virtualnoexcept

Clear the contents of the log buffer.

Reset the log buffer to an empty state.

Postcondition
The log buffer will be empty.

Implemented in embvm::CircularLogBufferLogger< TBufferSize, TLock >.

◆ dump()

template<typename TLock >
virtual void embvm::LoggerBase< TLock >::dump ( )
pure virtualnoexcept

Print the contents of the log buffer in the console.

When called, the contents of the log buffer will be echo'd to the console through printf. The entire log buffer will be displayed.

Derived classes must implement this function.

Implemented in embvm::CircularLogBufferLogger< TBufferSize, TLock >.

◆ echo() [1/2]

template<typename TLock >
bool embvm::LoggerBase< TLock >::echo ( ) const
inlinenoexcept

Check the echo setting.

Returns
true if echo to console is enabled, false if disabled.

References embvm::LoggerBase< TLock >::echo_.

◆ echo() [2/2]

template<typename TLock >
bool embvm::LoggerBase< TLock >::echo ( bool  en)
inlinenoexcept

Enable/disable echo to console.

Parameters
enEcho switch. If true, log statements will also be echo'd to the console through printf(). If false, log statements will only go to the log buffer.
Returns
true if echo to console is enabled, false if disabled.

References embvm::LoggerBase< TLock >::echo_.

◆ enabled() [1/2]

template<typename TLock >
bool embvm::LoggerBase< TLock >::enabled ( ) const
inlinenoexcept

Check if the log is enabled.

Returns
true if log output is enabled, false if it is disabled.

References embvm::LoggerBase< TLock >::enabled_.

◆ enabled() [2/2]

template<typename TLock >
bool embvm::LoggerBase< TLock >::enabled ( bool  en)
inlinenoexcept

Enable/disable logging.

Parameters
enEnable switch. If true, logging is enabled. If false, logging is disabled.
Returns
true if log output is enabled, false if it is disabled.

References embvm::LoggerBase< TLock >::enabled_.

◆ level() [1/2]

template<typename TLock >
logger::level embvm::LoggerBase< TLock >::level ( ) const
inlinenoexcept

Get the maximum log level (filtering)

Returns
the current log level maximum.

References embvm::LoggerBase< TLock >::level_.

◆ level() [2/2]

template<typename TLock >
logger::level embvm::LoggerBase< TLock >::level ( logger::level  l)
inlinenoexcept

Set the maximum log level (filtering)

Parameters
lThe maximum log level. Levels grater than l will not be added to the log buffer.
Returns
the current log level maximum.

References embvm::LoggerBase< TLock >::level_, and embvm::logger::LOG_LEVEL_LIMIT.

◆ log()

template<typename TLock >
template<typename... Args>
void embvm::LoggerBase< TLock >::log ( logger::level  l,
const char *  fmt,
const Args &...  args 
)
inlinenoexcept

Add data to the log buffer.

Template Parameters
ArgsVariadic template args. Will be deduced by the compiler. Enables support for a variadic function template.
Parameters
lThe log level associated with this statement.
fmtThe log format string.
argsThe variadic arguments that are associated with the format string.

References embvm::LoggerBase< TLock >::echo_, embvm::LoggerBase< TLock >::enabled_, fctprintf(), embvm::LoggerBase< TLock >::level_, embvm::LoggerBase< TLock >::log_putc_bounce(), embvm::LoggerBase< TLock >::mutex_, printf, embvm::LoggerBase< TLock >::system_clock_, embvm::clk::SystemClock::ticks(), and embvm::logger::to_short_c_str().

◆ log_putc()

template<typename TLock >
virtual void embvm::LoggerBase< TLock >::log_putc ( char  c)
protectedpure virtual

Log buffer putc function.

This function adds a character to the underlying log buffer.

This function is used with the fctprintf() interface to output to the log buffer. This enables the framework to reuse the same print formatting for both logging and printf().

Derived classes must implement this function.

Parameters
cThe character to insert into the log buffer.

Implemented in embvm::CircularLogBufferLogger< TBufferSize, TLock >.

◆ log_putc_bounce()

template<typename TLock >
static void embvm::LoggerBase< TLock >::log_putc_bounce ( char  c,
void *  this_ptr 
)
inlinestaticprotected

putc bounce function

This is a bounce function which registers with the C printf API. We use the private parameter to store the this pointer so we can get back to our logger's putc instance.

Parameters
cThe character to log.
this_ptrThe this pointer of the logger instance. Used to invoke log_putc() on the correct instance.

Referenced by embvm::LoggerBase< TLock >::log().

◆ setClock()

template<typename TLock >
void embvm::LoggerBase< TLock >::setClock ( embvm::clk::SystemClock clk)
inlinenoexcept

Set the system clock.

Parameters
clkThe system clock instance to use for timestamping.

References embvm::LoggerBase< TLock >::system_clock_.

◆ size()

template<typename TLock >
virtual size_t embvm::LoggerBase< TLock >::size ( ) const
pure virtualnoexcept

Get the current log buffer size.

Derived classes must implement this function.

Returns
The current size of the log buffer, in bytes.

Implemented in embvm::CircularLogBufferLogger< TBufferSize, TLock >.

Member Data Documentation

◆ echo_

template<typename TLock >
bool embvm::LoggerBase< TLock >::echo_ = LOG_ECHO_EN_DEFAULT
private

Console echoing.

If true, log statements will be printed to the console through printf().

Referenced by embvm::LoggerBase< TLock >::echo(), and embvm::LoggerBase< TLock >::log().

◆ enabled_

template<typename TLock >
bool embvm::LoggerBase< TLock >::enabled_ = LOG_EN_DEFAULT
private

Indicates whether logging is currently enabled.

Referenced by embvm::LoggerBase< TLock >::enabled(), and embvm::LoggerBase< TLock >::log().

◆ level_

template<typename TLock >
logger::level embvm::LoggerBase< TLock >::level_ = logger::LOG_LEVEL_LIMIT
private

The current log level.

Levels greater than the current setting will be filtered out.

Referenced by embvm::LoggerBase< TLock >::level(), and embvm::LoggerBase< TLock >::log().

◆ mutex_

template<typename TLock >
TLock embvm::LoggerBase< TLock >::mutex_
private

Mutex which protects the log buffer.

Referenced by embvm::LoggerBase< TLock >::log().

◆ system_clock_

template<typename TLock >
embvm::clk::SystemClock* embvm::LoggerBase< TLock >::system_clock_ = nullptr
private

The system clock instance, used for timestamping.

Referenced by embvm::LoggerBase< TLock >::log(), and embvm::LoggerBase< TLock >::setClock().

◆ embvm::PlatformLogger_t

class embvm::PlatformLogger_t

template<class TLogger>
class embvm::PlatformLogger_t< TLogger >

Declare a static platform logger instance.

This class is used to declare a static platform logger instance.

Define a platform logger which is templated on the log type:

using PlatformLogger = PlatformLogger_t<CircularLogBufferLogger<8 * 1024>>;

This PlatformLogger type will then work with the logging macros (loginfo(), etc.).

The instance can also be grabbed manually:

PlatformLogger::inst().setClock(clk.value());

Public Member Functions

 PlatformLogger_t ()=default
 
 ~PlatformLogger_t ()=default
 

Static Public Member Functions

static TLogger & inst ()
 

Constructor & Destructor Documentation

◆ PlatformLogger_t()

template<class TLogger>
embvm::PlatformLogger_t< TLogger >::PlatformLogger_t ( )
default

◆ ~PlatformLogger_t()

template<class TLogger>
embvm::PlatformLogger_t< TLogger >::~PlatformLogger_t ( )
default

Member Function Documentation

◆ inst()

Macro Definition Documentation

◆ LOG_ECHO_EN_DEFAULT

#define LOG_ECHO_EN_DEFAULT   false

Indicates that log statements should be echoed to the console If true, log statements will be echoed.

If false, log statements will only go to the log.

◆ LOG_EN_DEFAULT

#define LOG_EN_DEFAULT   true

Whether the logging module is enabled automatically on boot.

◆ LOG_LEVEL

#define LOG_LEVEL   LOG_LEVEL_DEBUG

Default maximum log level.

This is the maximum log level that will be compiled in. To set a custom log level, define the LOG_LEVEL before including this header (e.g., as a compiler definition)

◆ LOG_LEVEL_COUNT

#define LOG_LEVEL_COUNT   (LOG_LEVEL_MAX + 1)

The number of possible log levels.

◆ LOG_LEVEL_CRITICAL

#define LOG_LEVEL_CRITICAL   1

Indicates the system is unusable, or an error that is unrecoverable.

◆ LOG_LEVEL_CRITICAL_PREFIX

#define LOG_LEVEL_CRITICAL_PREFIX   "!"

◆ LOG_LEVEL_DEBUG

#define LOG_LEVEL_DEBUG   5

Debug-level messages.

◆ LOG_LEVEL_DEBUG_PREFIX

#define LOG_LEVEL_DEBUG_PREFIX   "D"

◆ LOG_LEVEL_ERROR

#define LOG_LEVEL_ERROR   2

Indicates an error condition.

◆ LOG_LEVEL_ERROR_PREFIX

#define LOG_LEVEL_ERROR_PREFIX   "E"

◆ LOG_LEVEL_INFO

#define LOG_LEVEL_INFO   4

Informational messages.

◆ LOG_LEVEL_INFO_PREFIX

#define LOG_LEVEL_INFO_PREFIX   "I"

◆ LOG_LEVEL_INTERRUPT_PREFIX

#define LOG_LEVEL_INTERRUPT_PREFIX   "I"

◆ LOG_LEVEL_MAX

#define LOG_LEVEL_MAX   LOG_LEVEL_VERBOSE

The maximum log level that can be set.

◆ LOG_LEVEL_NAMES

#define LOG_LEVEL_NAMES
Value:
{ \
"off", "critical", "error", "warning", "info", "debug", "verbose" \
}

Users can override these default names with a compiler definition.

◆ LOG_LEVEL_OFF

#define LOG_LEVEL_OFF   0

Logging is disabled.

◆ LOG_LEVEL_SHORT_NAMES

#define LOG_LEVEL_SHORT_NAMES
Value:
{ \
}
#define LOG_LEVEL_DEBUG_PREFIX
Definition: _log_common_defs.h:37
#define LOG_LEVEL_WARNING_PREFIX
Definition: _log_common_defs.h:35
#define LOG_LEVEL_CRITICAL_PREFIX
Definition: _log_common_defs.h:33
#define LOG_LEVEL_VERBOSE_PREFIX
Definition: _log_common_defs.h:38
#define LOG_LEVEL_ERROR_PREFIX
Definition: _log_common_defs.h:34

Users can override these default short names with a compiler definition.

◆ LOG_LEVEL_VERBOSE

#define LOG_LEVEL_VERBOSE   6

Extra super verbose messages.

◆ LOG_LEVEL_VERBOSE_PREFIX

#define LOG_LEVEL_VERBOSE_PREFIX   "V"

◆ LOG_LEVEL_WARN

#define LOG_LEVEL_WARN   3

Indicates a warning condition.

◆ LOG_LEVEL_WARNING_PREFIX

#define LOG_LEVEL_WARNING_PREFIX   "W"

◆ logcritical

#define logcritical (   ...)    PlatformLogger::inst().log(embvm::logger::level::critical, __VA_ARGS__)

◆ logdebug

#define logdebug (   ...)    PlatformLogger::inst().log(embvm::logger::level::debug, __VA_ARGS__)

◆ logerror

#define logerror (   ...)    PlatformLogger::inst().log(embvm::logger::level::error, __VA_ARGS__)

◆ loginfo

#define loginfo (   ...)    PlatformLogger::inst().log(embvm::logger::level::info, __VA_ARGS__)

◆ logverbose

#define logverbose (   ...)    PlatformLogger::inst().log(embvm::logger::level::verbose, __VA_ARGS__)

◆ logwarn

#define logwarn (   ...)    PlatformLogger::inst().log(embvm::logger::level::warn, __VA_ARGS__)