|
Embedded Artistry Framework
Embedded Systems C++ Framework
|
Subsystem which provides logging support. More...
|
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__) |
Subsystem which provides logging support.
| class embvm::CircularLogBufferLogger |
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.
| TBufferSize | Defines the size of the circular log buffer. Set to 0 to disable logging completely (for memory constrained systems). |
| TLock | the 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. using PlatformLogger = |

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} |
|
inline |
Default constructor.
|
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.
| clk | The system clock instance to use for timestamping. |
|
inlineexplicitnoexcept |
Initialize the circular log buffer with options.
| enable | If 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. |
| l | Runtime log filtering level. Levels greater than the target will not be output to the log buffer. |
| echo | If 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. |
|
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.
| clk | The system clock instance to use for timestamping. |
| enable | If 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. |
| l | Runtime log filtering level. Levels greater than the target will not be output to the log buffer. |
| echo | If 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. |
|
defaultnoexcept |
Default destructor.
|
inlinefinalvirtualnoexcept |
Get the log buffer capacity.
Derived classes must implement this function.
Implements embvm::LoggerBase< TLock >.
References embvm::CircularLogBufferLogger< TBufferSize, TLock >::log_buffer_.
|
inlinefinalvirtualnoexcept |
Clear the contents of the log buffer.
Reset the log buffer to an empty state.
Implements embvm::LoggerBase< TLock >.
References embvm::CircularLogBufferLogger< TBufferSize, TLock >::log_buffer_.
|
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.
|
inlinenoexceptinherited |
Check the echo setting.
References embvm::LoggerBase< TLock >::echo_.
|
inlinenoexceptinherited |
Enable/disable echo to console.
| en | Echo 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. |
References embvm::LoggerBase< TLock >::echo_.
|
inlinenoexceptinherited |
Check if the log is enabled.
References embvm::LoggerBase< TLock >::enabled_.
|
inlinenoexceptinherited |
Enable/disable logging.
| en | Enable switch. If true, logging is enabled. If false, logging is disabled. |
References embvm::LoggerBase< TLock >::enabled_.
|
inlinenoexceptinherited |
Get the maximum log level (filtering)
References embvm::LoggerBase< TLock >::level_.
|
inlinenoexceptinherited |
Set the maximum log level (filtering)
| l | The maximum log level. Levels grater than l will not be added to the log buffer. |
References embvm::LoggerBase< TLock >::level_, and embvm::logger::LOG_LEVEL_LIMIT.
|
inlinenoexceptinherited |
Add data to the log buffer.
| Args | Variadic template args. Will be deduced by the compiler. Enables support for a variadic function template. |
| l | The log level associated with this statement. |
| fmt | The log format string. |
| args | The 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().
|
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.
| c | The character to insert into the log buffer. |
Implements embvm::LoggerBase< TLock >.
References embvm::CircularLogBufferLogger< TBufferSize, TLock >::log_buffer_.
|
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.
| c | The character to log. |
| this_ptr | The this pointer of the logger instance. Used to invoke log_putc() on the correct instance. |
Referenced by embvm::LoggerBase< TLock >::log().
|
inlinenoexceptinherited |
Set the system clock.
| clk | The system clock instance to use for timestamping. |
References embvm::LoggerBase< TLock >::system_clock_.
|
inlinefinalvirtualnoexcept |
Get the current log buffer size.
Derived classes must implement this function.
Implements embvm::LoggerBase< TLock >.
References embvm::CircularLogBufferLogger< TBufferSize, TLock >::log_buffer_.
|
private |
|
private |
Referenced by embvm::CircularLogBufferLogger< TBufferSize, TLock >::capacity(), embvm::CircularLogBufferLogger< TBufferSize, TLock >::clear(), embvm::CircularLogBufferLogger< TBufferSize, TLock >::dump(), embvm::CircularLogBufferLogger< TBufferSize, TLock >::log_putc(), and embvm::CircularLogBufferLogger< TBufferSize, TLock >::size().
| class embvm::LoggerBase |
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.
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.
Do declare your own logger type, inherit from this base class:
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:
| TLock | the type of lock to use with the LoggerBase. Locking can be disabled by using the embutil::nop_lock type. |

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::SystemClock * | system_clock_ = nullptr |
| The system clock instance, used for timestamping. More... | |
|
protecteddefault |
Default constructor.
|
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.
| clk | The system clock instance to use for timestamping. |
|
inlineexplicitprotectednoexcept |
Initialize the logger with options.
| enable | If 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. |
| l | Runtime log filtering level. Levels greater than the target will not be output to the log buffer. |
| echo | If 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. |
|
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.
| clk | The system clock instance to use for timestamping. |
| enable | If 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. |
| l | Runtime log filtering level. Levels greater than the target will not be output to the log buffer. |
| echo | If 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. |
|
protectedvirtualdefault |
Default destructor.
|
pure virtualnoexcept |
Get the log buffer capacity.
Derived classes must implement this function.
Implemented in embvm::CircularLogBufferLogger< TBufferSize, TLock >.
|
pure virtualnoexcept |
Clear the contents of the log buffer.
Reset the log buffer to an empty state.
Implemented in embvm::CircularLogBufferLogger< TBufferSize, TLock >.
|
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 >.
|
inlinenoexcept |
Check the echo setting.
References embvm::LoggerBase< TLock >::echo_.
|
inlinenoexcept |
Enable/disable echo to console.
| en | Echo 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. |
References embvm::LoggerBase< TLock >::echo_.
|
inlinenoexcept |
Check if the log is enabled.
References embvm::LoggerBase< TLock >::enabled_.
|
inlinenoexcept |
Enable/disable logging.
| en | Enable switch. If true, logging is enabled. If false, logging is disabled. |
References embvm::LoggerBase< TLock >::enabled_.
|
inlinenoexcept |
Get the maximum log level (filtering)
References embvm::LoggerBase< TLock >::level_.
|
inlinenoexcept |
Set the maximum log level (filtering)
| l | The maximum log level. Levels grater than l will not be added to the log buffer. |
References embvm::LoggerBase< TLock >::level_, and embvm::logger::LOG_LEVEL_LIMIT.
|
inlinenoexcept |
Add data to the log buffer.
| Args | Variadic template args. Will be deduced by the compiler. Enables support for a variadic function template. |
| l | The log level associated with this statement. |
| fmt | The log format string. |
| args | The 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().
|
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.
| c | The character to insert into the log buffer. |
Implemented in embvm::CircularLogBufferLogger< TBufferSize, TLock >.
|
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.
| c | The character to log. |
| this_ptr | The this pointer of the logger instance. Used to invoke log_putc() on the correct instance. |
Referenced by embvm::LoggerBase< TLock >::log().
|
inlinenoexcept |
Set the system clock.
| clk | The system clock instance to use for timestamping. |
References embvm::LoggerBase< TLock >::system_clock_.
|
pure virtualnoexcept |
Get the current log buffer size.
Derived classes must implement this function.
Implemented in embvm::CircularLogBufferLogger< TBufferSize, TLock >.
|
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().
|
private |
Indicates whether logging is currently enabled.
Referenced by embvm::LoggerBase< TLock >::enabled(), and embvm::LoggerBase< TLock >::log().
|
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().
|
private |
Mutex which protects the log buffer.
Referenced by embvm::LoggerBase< TLock >::log().
|
private |
The system clock instance, used for timestamping.
Referenced by embvm::LoggerBase< TLock >::log(), and embvm::LoggerBase< TLock >::setClock().
| class embvm::PlatformLogger_t |
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:
This PlatformLogger type will then work with the logging macros (loginfo(), etc.).
The instance can also be grabbed manually:
Public Member Functions | |
| PlatformLogger_t ()=default | |
| ~PlatformLogger_t ()=default | |
Static Public Member Functions | |
| static TLogger & | inst () |
|
default |
|
default |
|
inlinestatic |
| #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.
| #define LOG_EN_DEFAULT true |
Whether the logging module is enabled automatically on boot.
| #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)
| #define LOG_LEVEL_COUNT (LOG_LEVEL_MAX + 1) |
The number of possible log levels.
| #define LOG_LEVEL_CRITICAL 1 |
Indicates the system is unusable, or an error that is unrecoverable.
| #define LOG_LEVEL_CRITICAL_PREFIX "!" |
| #define LOG_LEVEL_DEBUG 5 |
Debug-level messages.
| #define LOG_LEVEL_DEBUG_PREFIX "D" |
| #define LOG_LEVEL_ERROR 2 |
Indicates an error condition.
| #define LOG_LEVEL_ERROR_PREFIX "E" |
| #define LOG_LEVEL_INFO 4 |
Informational messages.
| #define LOG_LEVEL_INFO_PREFIX "I" |
| #define LOG_LEVEL_INTERRUPT_PREFIX "I" |
| #define LOG_LEVEL_MAX LOG_LEVEL_VERBOSE |
The maximum log level that can be set.
| #define LOG_LEVEL_NAMES |
Users can override these default names with a compiler definition.
| #define LOG_LEVEL_OFF 0 |
Logging is disabled.
| #define LOG_LEVEL_SHORT_NAMES |
Users can override these default short names with a compiler definition.
| #define LOG_LEVEL_VERBOSE 6 |
Extra super verbose messages.
| #define LOG_LEVEL_VERBOSE_PREFIX "V" |
| #define LOG_LEVEL_WARN 3 |
Indicates a warning condition.
| #define LOG_LEVEL_WARNING_PREFIX "W" |
| #define logcritical | ( | ... | ) | PlatformLogger::inst().log(embvm::logger::level::critical, __VA_ARGS__) |
| #define logdebug | ( | ... | ) | PlatformLogger::inst().log(embvm::logger::level::debug, __VA_ARGS__) |
| #define logerror | ( | ... | ) | PlatformLogger::inst().log(embvm::logger::level::error, __VA_ARGS__) |
| #define loginfo | ( | ... | ) | PlatformLogger::inst().log(embvm::logger::level::info, __VA_ARGS__) |
| #define logverbose | ( | ... | ) | PlatformLogger::inst().log(embvm::logger::level::verbose, __VA_ARGS__) |
| #define logwarn | ( | ... | ) | PlatformLogger::inst().log(embvm::logger::level::warn, __VA_ARGS__) |
1.8.15