PebbleOS v4.47.0-512-g5285d4236
Loading...
Searching...
No Matches
Logging

Leveled logging to the serial console and to flash. More...

Modules

 Backends
 Outputs of log messages.
 
 Flash backend
 Log messages stored in the debug flash region, one generation per boot.
 
 Binary logging
 Wire format of binary log messages.
 
 Log hashing
 Compile-time replacement of log strings by tokens (CONFIG_LOG_HASHED).
 

Macros

#define LOG_BUFFER_LENGTH   128
 Size of the buffer a log message is formatted into, header included.
 
#define LOGGING_MIN_STACK_FOR_SPRINTF   240
 Minimum free stack, in bytes, to format a message; below it the message is replaced.
 
#define LOGGING_STACK_FULL_MSG   ((const char *)" [STK FULL]")
 Message logged instead when the stack is too full to format it.
 
#define LOG_LEVEL_ALWAYS   0
 Level of messages that are never filtered.
 
#define LOG_LEVEL_ERROR   1
 Error level.
 
#define LOG_LEVEL_WARNING   50
 Warning level.
 
#define LOG_LEVEL_INFO   100
 Info level.
 
#define LOG_LEVEL_DEBUG   200
 Debug level.
 
#define LOG_LEVEL_DEBUG_VERBOSE   255
 Verbose debug level.
 
#define LOG_LEVEL_OFF   (-1)
 Module level that disables every message of the module.
 
#define DEFAULT_LOG_LEVEL   LOG_LEVEL_DEBUG
 Compile-time level of files without a log module, from CONFIG_DEFAULT_LOG_LEVEL.
 
#define PBL_LOG_MODULE_DEFINE(name, level)    [[maybe_unused]] static const int16_t _pbl_log_module_level = 0
 Put the current file in a log module, defining the module.
 
#define PBL_LOG_MODULE_DECLARE(name, level)   PBL_LOG_MODULE_DEFINE(name, level)
 Put the current file in a log module defined in another file.
 
#define PBL_LOG_MODULE_LEVEL_GET(name)
 Get the runtime level of a module built with CONFIG_<module>_LOG_LEVEL_RUNTIME.
 
#define PBL_LOG_MODULE_LEVEL_SET(name, level)
 Set the runtime level of a module built with CONFIG_<module>_LOG_LEVEL_RUNTIME.
 
#define PBL_SHOULD_LOG(level)
 Check whether the current file logs messages of a level.
 
#define PBL_LOG_COLOR(level, color, fmt, ...)
 Log a message with an explicit level and color, possibly queued.
 
#define PBL_LOG_COLOR_SYNC(level, color, fmt, ...)   PBL_LOG_COLOR(level, color, fmt, ##__VA_ARGS__)
 Log a message with an explicit level and color, sent before returning.
 
#define PBL_LOG_ALWAYS(fmt, ...)    PBL_LOG_COLOR(LOG_LEVEL_ALWAYS, LOG_COLOR_FOR_ALWAYS, fmt, ##__VA_ARGS__)
 Log a message that is never filtered, possibly queued.
 
#define PBL_LOG_ERR(fmt, ...)    PBL_LOG_COLOR(LOG_LEVEL_ERROR, LOG_COLOR_FOR_ERROR, fmt, ##__VA_ARGS__)
 Log an error, possibly queued.
 
#define PBL_LOG_WRN(fmt, ...)    PBL_LOG_COLOR(LOG_LEVEL_WARNING, LOG_COLOR_FOR_WARNING, fmt, ##__VA_ARGS__)
 Log a warning, possibly queued.
 
#define PBL_LOG_INFO(fmt, ...)   PBL_LOG_COLOR(LOG_LEVEL_INFO, LOG_COLOR_FOR_INFO, fmt, ##__VA_ARGS__)
 Log an attention-worthy event, possibly queued.
 
#define PBL_LOG_DBG(fmt, ...)    PBL_LOG_COLOR(LOG_LEVEL_DEBUG, LOG_COLOR_FOR_DEBUG, fmt, ##__VA_ARGS__)
 Log a routine debug message, possibly queued.
 
#define PBL_LOG_VERBOSE(fmt, ...)    PBL_LOG_COLOR(LOG_LEVEL_DEBUG_VERBOSE, LOG_COLOR_FOR_VERBOSE, fmt, ##__VA_ARGS__)
 Log a verbose debug message, possibly queued.
 
#define PBL_LOG_FAULT(fmt, ...)   pbl_log_fault(__FILE_NAME__, __LINE__, fmt, ##__VA_ARGS__)
 Log a message from a fault handler, sent before returning.
 
#define PBL_LOG_SYNC_ALWAYS(fmt, ...)    PBL_LOG_COLOR_SYNC(LOG_LEVEL_ALWAYS, LOG_COLOR_FOR_ALWAYS, fmt, ##__VA_ARGS__)
 Log a message that is never filtered, sent before returning.
 
#define PBL_LOG_SYNC_ERR(fmt, ...)    PBL_LOG_COLOR_SYNC(LOG_LEVEL_ERROR, LOG_COLOR_FOR_ERROR, fmt, ##__VA_ARGS__)
 Log an error, sent before returning.
 
#define PBL_LOG_SYNC_WRN(fmt, ...)    PBL_LOG_COLOR_SYNC(LOG_LEVEL_WARNING, LOG_COLOR_FOR_WARNING, fmt, ##__VA_ARGS__)
 Log a warning, sent before returning.
 
#define PBL_LOG_SYNC_INFO(fmt, ...)    PBL_LOG_COLOR_SYNC(LOG_LEVEL_INFO, LOG_COLOR_FOR_INFO, fmt, ##__VA_ARGS__)
 Log an attention-worthy event, sent before returning.
 
#define PBL_LOG_SYNC_DBG(fmt, ...)    PBL_LOG_COLOR_SYNC(LOG_LEVEL_DEBUG, LOG_COLOR_FOR_DEBUG, fmt, ##__VA_ARGS__)
 Log a routine debug message, sent before returning.
 
#define PBL_LOG_SYNC_VERBOSE(fmt, ...)    PBL_LOG_COLOR_SYNC(LOG_LEVEL_DEBUG_VERBOSE, LOG_COLOR_FOR_VERBOSE, fmt, ##__VA_ARGS__)
 Log a verbose debug message, sent before returning.
 
#define PBL_LOG_HEXDUMP(level, data, length)
 Hex dump data with an explicit level, sent before returning.
 
#define PBL_LOG_HEXDUMP_ERR(data, length)   PBL_LOG_HEXDUMP(LOG_LEVEL_ERROR, data, length)
 Hex dump data as an error.
 
#define PBL_LOG_HEXDUMP_WRN(data, length)   PBL_LOG_HEXDUMP(LOG_LEVEL_WARNING, data, length)
 Hex dump data as a warning.
 
#define PBL_LOG_HEXDUMP_INFO(data, length)   PBL_LOG_HEXDUMP(LOG_LEVEL_INFO, data, length)
 Hex dump data as an attention-worthy event.
 
#define PBL_LOG_HEXDUMP_DBG(data, length)   PBL_LOG_HEXDUMP(LOG_LEVEL_DEBUG, data, length)
 Hex dump data as a routine debug message.
 
#define PBL_LOG_HEXDUMP_VERBOSE(data, length)   PBL_LOG_HEXDUMP(LOG_LEVEL_DEBUG_VERBOSE, data, length)
 Hex dump data as a verbose debug message.
 

Functions

void pbl_log_hashed_async (const uint32_t packed_loghash,...)
 Log a hashed message, possibly queued.
 
void pbl_log_hashed_sync (const uint32_t packed_loghash,...)
 Log a hashed message, sent before returning.
 
void pbl_log_hashed_filtered_async (const uint32_t packed_loghash,...)
 pbl_log_hashed_async() for modules with a runtime level, bypassing the sink filters.
 
void pbl_log_hashed_filtered_sync (const uint32_t packed_loghash,...)
 pbl_log_hashed_sync() for modules with a runtime level, bypassing the sink filters.
 
void pbl_log_hashed_core (const uint32_t core_number, const uint32_t packed_loghash,...)
 Log a hashed message from another core, possibly queued.
 
void pbl_log_hashed_vargs (const bool async, const uint32_t core_number, const uint32_t packed_loghash, va_list fmt_args)
 Log a hashed message from another core, with a va_list.
 
void pbl_log_vargs (uint8_t log_level, const char *src_filename, int src_line_number, const char *fmt, va_list args)
 Log a message with a va_list, possibly queued.
 
void pbl_log (uint8_t log_level, const char *src_filename, int src_line_number, const char *fmt,...)
 Log a message, possibly queued.
 
void pbl_log_sync (uint8_t log_level, const char *src_filename, int src_line_number, const char *fmt,...)
 Log a message, sent before returning.
 
void pbl_log_filtered (uint8_t log_level, const char *src_filename, int src_line_number, const char *fmt,...)
 pbl_log() for modules with a runtime level, bypassing the sink filters.
 
void pbl_log_filtered_sync (uint8_t log_level, const char *src_filename, int src_line_number, const char *fmt,...)
 pbl_log_sync() for modules with a runtime level, bypassing the sink filters.
 
void pbl_log_fault (const char *src_filename, int src_line_number, const char *fmt,...)
 Log a message from a fault handler, sent before returning.
 
void pbl_log_hexdump (uint8_t log_level, const char *src_filename, int src_line_number, const void *data, size_t length)
 Log data as xxd-style lines of 16 bytes, sent before returning.
 
int pbl_log_binary_format (char *buffer, int buffer_len, const uint8_t log_level, const char *src_filename_path, int src_line_number, const char *fmt, va_list args)
 Format a message as a binary log record.
 
int pbl_log_get_bin_format (char *buffer, int buffer_len, const uint8_t log_level, const char *src_filename_path, int src_line_number, const char *fmt,...)
 pbl_log_binary_format() with variadic arguments.
 

Log colors

Color names stored with hashed messages, used by the host console.

#define LOG_COLOR_BLACK   "BLACK"
 Black, hardly readable.
 
#define LOG_COLOR_RED   "RED"
 Red.
 
#define LOG_COLOR_GREEN   "GREEN"
 Green.
 
#define LOG_COLOR_YELLOW   "YELLOW"
 Yellow.
 
#define LOG_COLOR_BLUE   "BLUE"
 Blue.
 
#define LOG_COLOR_MAGENTA   "MAGENTA"
 Magenta.
 
#define LOG_COLOR_CYAN   "CYAN"
 Cyan.
 
#define LOG_COLOR_GREY   "GREY"
 Grey.
 
#define LOG_COLOR_LIGHT_GREY   "LIGHT_GREY"
 Light grey, reserved for bold like the other light colors.
 
#define LOG_COLOR_LIGHT_RED   "LIGHT_RED"
 Light red.
 
#define LOG_COLOR_LIGHT_GREEN   "LIGHT_GREEN"
 Light green.
 
#define LOG_COLOR_LIGHT_YELLOW   "LIGHT_YELLOW"
 Light yellow.
 
#define LOG_COLOR_LIGHT_BLUE   "LIGHT_BLUE"
 Light blue.
 
#define LOG_COLOR_LIGHT_MAGENTA   "LIGHT_MAGENTA"
 Light magenta.
 
#define LOG_COLOR_LIGHT_CYAN   "LIGHT_CYAN"
 Light cyan.
 
#define LOG_COLOR_WHITE   "WHITE"
 White.
 
#define LOG_COLOR_FOR_ALWAYS   LOG_COLOR_BLUE
 Color of LOG_LEVEL_ALWAYS messages.
 
#define LOG_COLOR_FOR_ERROR   LOG_COLOR_RED
 Color of LOG_LEVEL_ERROR messages.
 
#define LOG_COLOR_FOR_WARNING   LOG_COLOR_YELLOW
 Color of LOG_LEVEL_WARNING messages.
 
#define LOG_COLOR_FOR_INFO   LOG_COLOR_GREEN
 Color of LOG_LEVEL_INFO messages.
 
#define LOG_COLOR_FOR_DEBUG   LOG_COLOR_GREY
 Color of LOG_LEVEL_DEBUG messages.
 
#define LOG_COLOR_FOR_VERBOSE   LOG_COLOR_GREY
 Color of LOG_LEVEL_DEBUG_VERBOSE messages.
 

Detailed Description

Leveled logging to the serial console and to flash.

Use the level-named macros: PBL_LOG_ERR() and PBL_LOG_WRN() for errors and warnings, PBL_LOG_DBG() for routine lifecycle and state-transition messages, and PBL_LOG_INFO() only for events that deserve attention in a default-level capture; code paths that can fire repeatedly in normal use must not log at INFO. PBL_LOG_ALWAYS() is never filtered.

Each source file can belong to a log module with a Kconfig level, generated by subsys/logging/Kconfig.template.log_level; messages above the module level are compiled out. Files without a module use DEFAULT_LOG_LEVEL. A module built with CONFIG_<module>_LOG_LEVEL_RUNTIME keeps all its messages and filters them at runtime, see PBL_LOG_MODULE_LEVEL_SET().

The async macros may queue the message when called from an interrupt or with interrupts or the scheduler locked; the sync variants send it before returning in every context, for fault paths. With CONFIG_LOG_HASHED the format strings are replaced by tokens at build time (see Log hashing), which limits them to 7 conversions, 2 of them %s, 32-bit arguments and no %%.

Note
Do not mix %s with %x or %X in one message; the log dehasher cannot decode it. Split the message instead.
PBL_LOG_MODULE_DEFINE(my_service, CONFIG_MY_SERVICE_LOG_LEVEL);
PBL_LOG_DBG("Connected, interval %u ms", interval_ms);
PBL_LOG_WRN("Write failed: %d", rc);
PBL_LOG_ERR("Bad header 0x%" PRIx32, hdr);
PBL_LOG_DBG("Peer %s", name);
#define PBL_LOG_WRN(fmt,...)
Log a warning, possibly queued.
Definition logging.h:547
#define PBL_LOG_ERR(fmt,...)
Log an error, possibly queued.
Definition logging.h:539
#define PBL_LOG_MODULE_DEFINE(name, level)
Put the current file in a log module, defining the module.
Definition logging.h:396
#define PBL_LOG_DBG(fmt,...)
Log a routine debug message, possibly queued.
Definition logging.h:562

Other files of the same module use PBL_LOG_MODULE_DECLARE() with the same arguments.

Macro Definition Documentation

◆ DEFAULT_LOG_LEVEL

#define DEFAULT_LOG_LEVEL   LOG_LEVEL_DEBUG

Compile-time level of files without a log module, from CONFIG_DEFAULT_LOG_LEVEL.

◆ LOG_BUFFER_LENGTH

#define LOG_BUFFER_LENGTH   128

Size of the buffer a log message is formatted into, header included.

◆ LOG_COLOR_BLACK

#define LOG_COLOR_BLACK   "BLACK"

Black, hardly readable.

◆ LOG_COLOR_BLUE

#define LOG_COLOR_BLUE   "BLUE"

Blue.

◆ LOG_COLOR_CYAN

#define LOG_COLOR_CYAN   "CYAN"

Cyan.

◆ LOG_COLOR_FOR_ALWAYS

#define LOG_COLOR_FOR_ALWAYS   LOG_COLOR_BLUE

Color of LOG_LEVEL_ALWAYS messages.

◆ LOG_COLOR_FOR_DEBUG

#define LOG_COLOR_FOR_DEBUG   LOG_COLOR_GREY

Color of LOG_LEVEL_DEBUG messages.

◆ LOG_COLOR_FOR_ERROR

#define LOG_COLOR_FOR_ERROR   LOG_COLOR_RED

Color of LOG_LEVEL_ERROR messages.

◆ LOG_COLOR_FOR_INFO

#define LOG_COLOR_FOR_INFO   LOG_COLOR_GREEN

Color of LOG_LEVEL_INFO messages.

◆ LOG_COLOR_FOR_VERBOSE

#define LOG_COLOR_FOR_VERBOSE   LOG_COLOR_GREY

Color of LOG_LEVEL_DEBUG_VERBOSE messages.

◆ LOG_COLOR_FOR_WARNING

#define LOG_COLOR_FOR_WARNING   LOG_COLOR_YELLOW

Color of LOG_LEVEL_WARNING messages.

◆ LOG_COLOR_GREEN

#define LOG_COLOR_GREEN   "GREEN"

Green.

◆ LOG_COLOR_GREY

#define LOG_COLOR_GREY   "GREY"

Grey.

◆ LOG_COLOR_LIGHT_BLUE

#define LOG_COLOR_LIGHT_BLUE   "LIGHT_BLUE"

Light blue.

◆ LOG_COLOR_LIGHT_CYAN

#define LOG_COLOR_LIGHT_CYAN   "LIGHT_CYAN"

Light cyan.

◆ LOG_COLOR_LIGHT_GREEN

#define LOG_COLOR_LIGHT_GREEN   "LIGHT_GREEN"

Light green.

◆ LOG_COLOR_LIGHT_GREY

#define LOG_COLOR_LIGHT_GREY   "LIGHT_GREY"

Light grey, reserved for bold like the other light colors.

Use sparingly.

◆ LOG_COLOR_LIGHT_MAGENTA

#define LOG_COLOR_LIGHT_MAGENTA   "LIGHT_MAGENTA"

Light magenta.

◆ LOG_COLOR_LIGHT_RED

#define LOG_COLOR_LIGHT_RED   "LIGHT_RED"

Light red.

◆ LOG_COLOR_LIGHT_YELLOW

#define LOG_COLOR_LIGHT_YELLOW   "LIGHT_YELLOW"

Light yellow.

◆ LOG_COLOR_MAGENTA

#define LOG_COLOR_MAGENTA   "MAGENTA"

Magenta.

◆ LOG_COLOR_RED

#define LOG_COLOR_RED   "RED"

Red.

◆ LOG_COLOR_WHITE

#define LOG_COLOR_WHITE   "WHITE"

White.

◆ LOG_COLOR_YELLOW

#define LOG_COLOR_YELLOW   "YELLOW"

Yellow.

◆ LOG_LEVEL_ALWAYS

#define LOG_LEVEL_ALWAYS   0

Level of messages that are never filtered.

◆ LOG_LEVEL_DEBUG

#define LOG_LEVEL_DEBUG   200

Debug level.

◆ LOG_LEVEL_DEBUG_VERBOSE

#define LOG_LEVEL_DEBUG_VERBOSE   255

Verbose debug level.

◆ LOG_LEVEL_ERROR

#define LOG_LEVEL_ERROR   1

Error level.

◆ LOG_LEVEL_INFO

#define LOG_LEVEL_INFO   100

Info level.

◆ LOG_LEVEL_OFF

#define LOG_LEVEL_OFF   (-1)

Module level that disables every message of the module.

◆ LOG_LEVEL_WARNING

#define LOG_LEVEL_WARNING   50

Warning level.

◆ LOGGING_MIN_STACK_FOR_SPRINTF

#define LOGGING_MIN_STACK_FOR_SPRINTF   240

Minimum free stack, in bytes, to format a message; below it the message is replaced.

◆ LOGGING_STACK_FULL_MSG

#define LOGGING_STACK_FULL_MSG   ((const char *)" [STK FULL]")

Message logged instead when the stack is too full to format it.

◆ PBL_LOG_ALWAYS

#define PBL_LOG_ALWAYS (   fmt,
  ... 
)     PBL_LOG_COLOR(LOG_LEVEL_ALWAYS, LOG_COLOR_FOR_ALWAYS, fmt, ##__VA_ARGS__)

Log a message that is never filtered, possibly queued.

Parameters
fmtprintf-style format, a string literal.
...Format arguments.

◆ PBL_LOG_COLOR

#define PBL_LOG_COLOR (   level,
  color,
  fmt,
  ... 
)
Value:
do { \
if (0) { \
_pbl_log_unused(fmt, ##__VA_ARGS__); \
} \
} while (0)

Log a message with an explicit level and color, possibly queued.

Prefer the level-named macros.

Parameters
levelLevel, one of the LOG_LEVEL_ values.
colorColor, one of the LOG_COLOR_ values.
fmtprintf-style format, a string literal.
...Format arguments.

◆ PBL_LOG_COLOR_SYNC

#define PBL_LOG_COLOR_SYNC (   level,
  color,
  fmt,
  ... 
)    PBL_LOG_COLOR(level, color, fmt, ##__VA_ARGS__)

Log a message with an explicit level and color, sent before returning.

Prefer the level-named macros.

Parameters
levelLevel, one of the LOG_LEVEL_ values.
colorColor, one of the LOG_COLOR_ values.
fmtprintf-style format, a string literal.
...Format arguments.

◆ PBL_LOG_DBG

#define PBL_LOG_DBG (   fmt,
  ... 
)     PBL_LOG_COLOR(LOG_LEVEL_DEBUG, LOG_COLOR_FOR_DEBUG, fmt, ##__VA_ARGS__)

Log a routine debug message, possibly queued.

Parameters
fmtprintf-style format, a string literal.
...Format arguments.

◆ PBL_LOG_ERR

#define PBL_LOG_ERR (   fmt,
  ... 
)     PBL_LOG_COLOR(LOG_LEVEL_ERROR, LOG_COLOR_FOR_ERROR, fmt, ##__VA_ARGS__)

Log an error, possibly queued.

Parameters
fmtprintf-style format, a string literal.
...Format arguments.

◆ PBL_LOG_FAULT

#define PBL_LOG_FAULT (   fmt,
  ... 
)    pbl_log_fault(__FILE_NAME__, __LINE__, fmt, ##__VA_ARGS__)

Log a message from a fault handler, sent before returning.

Parameters
fmtprintf-style format, a string literal.
...Format arguments.

◆ PBL_LOG_HEXDUMP

#define PBL_LOG_HEXDUMP (   level,
  data,
  length 
)
Value:
do { \
if (0) { \
(void)(data); \
(void)(length); \
} \
} while (0)

Hex dump data with an explicit level, sent before returning.

Prefer the level-named macros.

Parameters
levelLevel, one of the LOG_LEVEL_ values.
dataData to dump.
lengthLength of data in bytes.

◆ PBL_LOG_HEXDUMP_DBG

#define PBL_LOG_HEXDUMP_DBG (   data,
  length 
)    PBL_LOG_HEXDUMP(LOG_LEVEL_DEBUG, data, length)

Hex dump data as a routine debug message.

Parameters
dataData to dump.
lengthLength of data in bytes.

◆ PBL_LOG_HEXDUMP_ERR

#define PBL_LOG_HEXDUMP_ERR (   data,
  length 
)    PBL_LOG_HEXDUMP(LOG_LEVEL_ERROR, data, length)

Hex dump data as an error.

Parameters
dataData to dump.
lengthLength of data in bytes.

◆ PBL_LOG_HEXDUMP_INFO

#define PBL_LOG_HEXDUMP_INFO (   data,
  length 
)    PBL_LOG_HEXDUMP(LOG_LEVEL_INFO, data, length)

Hex dump data as an attention-worthy event.

Parameters
dataData to dump.
lengthLength of data in bytes.

◆ PBL_LOG_HEXDUMP_VERBOSE

#define PBL_LOG_HEXDUMP_VERBOSE (   data,
  length 
)    PBL_LOG_HEXDUMP(LOG_LEVEL_DEBUG_VERBOSE, data, length)

Hex dump data as a verbose debug message.

Parameters
dataData to dump.
lengthLength of data in bytes.

◆ PBL_LOG_HEXDUMP_WRN

#define PBL_LOG_HEXDUMP_WRN (   data,
  length 
)    PBL_LOG_HEXDUMP(LOG_LEVEL_WARNING, data, length)

Hex dump data as a warning.

Parameters
dataData to dump.
lengthLength of data in bytes.

◆ PBL_LOG_INFO

#define PBL_LOG_INFO (   fmt,
  ... 
)    PBL_LOG_COLOR(LOG_LEVEL_INFO, LOG_COLOR_FOR_INFO, fmt, ##__VA_ARGS__)

Log an attention-worthy event, possibly queued.

Parameters
fmtprintf-style format, a string literal.
...Format arguments.

◆ PBL_LOG_MODULE_DECLARE

#define PBL_LOG_MODULE_DECLARE (   name,
  level 
)    PBL_LOG_MODULE_DEFINE(name, level)

Put the current file in a log module defined in another file.

Parameters
nameModule name, as given to PBL_LOG_MODULE_DEFINE().
levelKconfig level symbol, as given to PBL_LOG_MODULE_DEFINE().

◆ PBL_LOG_MODULE_DEFINE

#define PBL_LOG_MODULE_DEFINE (   name,
  level 
)     [[maybe_unused]] static const int16_t _pbl_log_module_level = 0

Put the current file in a log module, defining the module.

Use it once per module, in one source file, before any PBL_LOG macro.

Parameters
nameModule name, an identifier.
levelKconfig level symbol, CONFIG_<module>_LOG_LEVEL.

◆ PBL_LOG_MODULE_LEVEL_GET

#define PBL_LOG_MODULE_LEVEL_GET (   name)
Value:
({ \
extern _Atomic int16_t _pbl_log_runtime_level_##name; \
atomic_load_explicit(&_pbl_log_runtime_level_##name, memory_order_relaxed); \
})

Get the runtime level of a module built with CONFIG_<module>_LOG_LEVEL_RUNTIME.

Parameters
nameModule name.
Returns
Current level.

◆ PBL_LOG_MODULE_LEVEL_SET

#define PBL_LOG_MODULE_LEVEL_SET (   name,
  level 
)
Value:
do { \
extern _Atomic int16_t _pbl_log_runtime_level_##name; \
atomic_store_explicit(&_pbl_log_runtime_level_##name, (level), memory_order_relaxed); \
} while (0)

Set the runtime level of a module built with CONFIG_<module>_LOG_LEVEL_RUNTIME.

Messages above the level are dropped; the global sink levels no longer apply to the module.

Parameters
nameModule name.
levelNew level, one of the LOG_LEVEL_ values.

◆ PBL_LOG_SYNC_ALWAYS

#define PBL_LOG_SYNC_ALWAYS (   fmt,
  ... 
)     PBL_LOG_COLOR_SYNC(LOG_LEVEL_ALWAYS, LOG_COLOR_FOR_ALWAYS, fmt, ##__VA_ARGS__)

Log a message that is never filtered, sent before returning.

Parameters
fmtprintf-style format, a string literal.
...Format arguments.

◆ PBL_LOG_SYNC_DBG

#define PBL_LOG_SYNC_DBG (   fmt,
  ... 
)     PBL_LOG_COLOR_SYNC(LOG_LEVEL_DEBUG, LOG_COLOR_FOR_DEBUG, fmt, ##__VA_ARGS__)

Log a routine debug message, sent before returning.

Parameters
fmtprintf-style format, a string literal.
...Format arguments.

◆ PBL_LOG_SYNC_ERR

#define PBL_LOG_SYNC_ERR (   fmt,
  ... 
)     PBL_LOG_COLOR_SYNC(LOG_LEVEL_ERROR, LOG_COLOR_FOR_ERROR, fmt, ##__VA_ARGS__)

Log an error, sent before returning.

Parameters
fmtprintf-style format, a string literal.
...Format arguments.

◆ PBL_LOG_SYNC_INFO

#define PBL_LOG_SYNC_INFO (   fmt,
  ... 
)     PBL_LOG_COLOR_SYNC(LOG_LEVEL_INFO, LOG_COLOR_FOR_INFO, fmt, ##__VA_ARGS__)

Log an attention-worthy event, sent before returning.

Parameters
fmtprintf-style format, a string literal.
...Format arguments.

◆ PBL_LOG_SYNC_VERBOSE

#define PBL_LOG_SYNC_VERBOSE (   fmt,
  ... 
)     PBL_LOG_COLOR_SYNC(LOG_LEVEL_DEBUG_VERBOSE, LOG_COLOR_FOR_VERBOSE, fmt, ##__VA_ARGS__)

Log a verbose debug message, sent before returning.

Parameters
fmtprintf-style format, a string literal.
...Format arguments.

◆ PBL_LOG_SYNC_WRN

#define PBL_LOG_SYNC_WRN (   fmt,
  ... 
)     PBL_LOG_COLOR_SYNC(LOG_LEVEL_WARNING, LOG_COLOR_FOR_WARNING, fmt, ##__VA_ARGS__)

Log a warning, sent before returning.

Parameters
fmtprintf-style format, a string literal.
...Format arguments.

◆ PBL_LOG_VERBOSE

#define PBL_LOG_VERBOSE (   fmt,
  ... 
)     PBL_LOG_COLOR(LOG_LEVEL_DEBUG_VERBOSE, LOG_COLOR_FOR_VERBOSE, fmt, ##__VA_ARGS__)

Log a verbose debug message, possibly queued.

Parameters
fmtprintf-style format, a string literal.
...Format arguments.

◆ PBL_LOG_WRN

#define PBL_LOG_WRN (   fmt,
  ... 
)     PBL_LOG_COLOR(LOG_LEVEL_WARNING, LOG_COLOR_FOR_WARNING, fmt, ##__VA_ARGS__)

Log a warning, possibly queued.

Parameters
fmtprintf-style format, a string literal.
...Format arguments.

◆ PBL_SHOULD_LOG

#define PBL_SHOULD_LOG (   level)
Value:
((level) <= (_pbl_log_module_level != 0 ? _pbl_log_module_level : DEFAULT_LOG_LEVEL) && \
(_pbl_log_module_runtime_level == nullptr || \
(level) <= atomic_load_explicit(_pbl_log_module_runtime_level, memory_order_relaxed)))
#define DEFAULT_LOG_LEVEL
Compile-time level of files without a log module, from CONFIG_DEFAULT_LOG_LEVEL.
Definition logging.h:261

Check whether the current file logs messages of a level.

Applies the module (or default) compile-time level and the module runtime level, if any.

Parameters
levelLevel, one of the LOG_LEVEL_ values.

Function Documentation

◆ pbl_log()

void pbl_log ( uint8_t  log_level,
const char *  src_filename,
int  src_line_number,
const char *  fmt,
  ... 
)

Log a message, possibly queued.

Prefer the PBL_LOG macros, which filter by level and hash the format.

Parameters
log_levelLevel, one of the LOG_LEVEL_ values.
src_filenameSource file path.
src_line_numberSource line number.
fmtprintf-style format.
...Format arguments.

◆ pbl_log_binary_format()

int pbl_log_binary_format ( char *  buffer,
int  buffer_len,
const uint8_t  log_level,
const char *  src_filename_path,
int  src_line_number,
const char *  fmt,
va_list  args 
)

Format a message as a binary log record.

The record holds a timestamp, the level, the line number, the last 15 characters of the file name and the formatted message, truncated to fit.

Parameters
[out]bufferDestination, larger than the record header.
buffer_lenSize of buffer in bytes.
log_levelLevel, one of the LOG_LEVEL_ values.
src_filename_pathSource file path.
src_line_numberSource line number.
fmtprintf-style format.
argsFormat arguments.
Returns
Length of the record in bytes.

◆ pbl_log_fault()

void pbl_log_fault ( const char *  src_filename,
int  src_line_number,
const char *  fmt,
  ... 
)

Log a message from a fault handler, sent before returning.

For contexts where OS services can't be trusted: never filtered, never recorded to flash, and formatted on a small stack buffer. Prefer PBL_LOG_FAULT().

Parameters
src_filenameSource file name.
src_line_numberSource line number.
fmtprintf-style format.
...Format arguments.

◆ pbl_log_filtered()

void pbl_log_filtered ( uint8_t  log_level,
const char *  src_filename,
int  src_line_number,
const char *  fmt,
  ... 
)

pbl_log() for modules with a runtime level, bypassing the sink filters.

Parameters
log_levelLevel, one of the LOG_LEVEL_ values.
src_filenameSource file path.
src_line_numberSource line number.
fmtprintf-style format.
...Format arguments.

◆ pbl_log_filtered_sync()

void pbl_log_filtered_sync ( uint8_t  log_level,
const char *  src_filename,
int  src_line_number,
const char *  fmt,
  ... 
)

pbl_log_sync() for modules with a runtime level, bypassing the sink filters.

Parameters
log_levelLevel, one of the LOG_LEVEL_ values.
src_filenameSource file path.
src_line_numberSource line number.
fmtprintf-style format.
...Format arguments.

◆ pbl_log_get_bin_format()

int pbl_log_get_bin_format ( char *  buffer,
int  buffer_len,
const uint8_t  log_level,
const char *  src_filename_path,
int  src_line_number,
const char *  fmt,
  ... 
)

pbl_log_binary_format() with variadic arguments.

Parameters
[out]bufferDestination, larger than the record header.
buffer_lenSize of buffer in bytes.
log_levelLevel, one of the LOG_LEVEL_ values.
src_filename_pathSource file path.
src_line_numberSource line number.
fmtprintf-style format.
...Format arguments.
Returns
Length of the record in bytes.

◆ pbl_log_hashed_async()

void pbl_log_hashed_async ( const uint32_t  packed_loghash,
  ... 
)

Log a hashed message, possibly queued.

Called by the PBL_LOG macros.

Parameters
packed_loghashMessage token, see Log hashing.
...Message arguments, 32 bits each.

◆ pbl_log_hashed_core()

void pbl_log_hashed_core ( const uint32_t  core_number,
const uint32_t  packed_loghash,
  ... 
)

Log a hashed message from another core, possibly queued.

Parameters
core_numberCore number, already shifted to PACKED_CORE_OFFSET.
packed_loghashMessage token, see Log hashing.
...Message arguments, 32 bits each.

◆ pbl_log_hashed_filtered_async()

void pbl_log_hashed_filtered_async ( const uint32_t  packed_loghash,
  ... 
)

pbl_log_hashed_async() for modules with a runtime level, bypassing the sink filters.

Parameters
packed_loghashMessage token, see Log hashing.
...Message arguments, 32 bits each.

◆ pbl_log_hashed_filtered_sync()

void pbl_log_hashed_filtered_sync ( const uint32_t  packed_loghash,
  ... 
)

pbl_log_hashed_sync() for modules with a runtime level, bypassing the sink filters.

Parameters
packed_loghashMessage token, see Log hashing.
...Message arguments, 32 bits each.

◆ pbl_log_hashed_sync()

void pbl_log_hashed_sync ( const uint32_t  packed_loghash,
  ... 
)

Log a hashed message, sent before returning.

Called by the PBL_LOG_SYNC macros.

Parameters
packed_loghashMessage token, see Log hashing.
...Message arguments, 32 bits each.

◆ pbl_log_hashed_vargs()

void pbl_log_hashed_vargs ( const bool  async,
const uint32_t  core_number,
const uint32_t  packed_loghash,
va_list  fmt_args 
)

Log a hashed message from another core, with a va_list.

Parameters
asyncWhether the message may be queued.
core_numberCore number, already shifted to PACKED_CORE_OFFSET.
packed_loghashMessage token, see Log hashing.
fmt_argsMessage arguments, 32 bits each.

◆ pbl_log_hexdump()

void pbl_log_hexdump ( uint8_t  log_level,
const char *  src_filename,
int  src_line_number,
const void *  data,
size_t  length 
)

Log data as xxd-style lines of 16 bytes, sent before returning.

Each line has the offset, the bytes in hex and their printable ASCII characters. Prefer the PBL_LOG_HEXDUMP macros, which filter by level.

Parameters
log_levelLevel, one of the LOG_LEVEL_ values.
src_filenameSource file path.
src_line_numberSource line number.
dataData to dump.
lengthLength of data in bytes.

◆ pbl_log_sync()

void pbl_log_sync ( uint8_t  log_level,
const char *  src_filename,
int  src_line_number,
const char *  fmt,
  ... 
)

Log a message, sent before returning.

Parameters
log_levelLevel, one of the LOG_LEVEL_ values.
src_filenameSource file path.
src_line_numberSource line number.
fmtprintf-style format.
...Format arguments.

◆ pbl_log_vargs()

void pbl_log_vargs ( uint8_t  log_level,
const char *  src_filename,
int  src_line_number,
const char *  fmt,
va_list  args 
)

Log a message with a va_list, possibly queued.

Parameters
log_levelLevel, one of the LOG_LEVEL_ values.
src_filenameSource file path.
src_line_numberSource line number.
fmtprintf-style format.
argsFormat arguments.