PebbleOS v4.47.0-512-g5285d4236
Loading...
Searching...
No Matches
logging.h File Reference
#include <stdarg.h>
#include <stdatomic.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <pbl/kernel/compiler.h>

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.
 
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.
 

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.