Logging system for Uniot devices.
More...
|
| #define | __FUNC_NAME__ __FUNCTION__ |
| | Cross-platform function name macro.
|
| |
| #define | UNIOT_LOG_LEVEL_ERROR 0 |
| | Log level definitions.
|
| |
| #define | UNIOT_LOG_LEVEL_WARN 1 |
| |
| #define | UNIOT_LOG_LEVEL_INFO 2 |
| |
| #define | UNIOT_LOG_LEVEL_DEBUG 3 |
| |
| #define | UNIOT_LOG_LEVEL_TRACE 4 |
| |
| #define | UNIOT_LOG_STREAM Serial |
| | Default log level.
|
| |
| #define | UNIOT_LOG_BAUD_RATE 115200 |
| | Default baud rate for serial logging.
|
| |
| #define | UNIOT_LOG_BUF_SIZE 256 |
| | Maximum size of the logging buffer.
|
| |
| #define | UNIOT_LOG_SET_READY() |
| | Initialize the logging system.
|
| |
| #define | UNIOT_LOG_PRINT(...) |
| | Print to the logging stream.
|
| |
| #define | UNIOT_LOG_STRINGIFY_(x) |
| | Core logging macro.
|
| |
| #define | UNIOT_LOG_STRINGIFY(x) |
| |
| #define | UNIOT_LOG(log_type, log_fmt, log_arg...) |
| |
| #define | UNIOT_LOG_IF(log_type, log_cond, log_fmt, log_arg...) |
| | Conditional logging macro.
|
| |
| #define | UNIOT_LOG_ERROR(...) |
| | Log an ERROR level message Used for critical errors that may prevent normal operation. Only compiled if UNIOT_LOG_LEVEL is at least UNIOT_LOG_LEVEL_ERROR.
|
| |
| #define | UNIOT_LOG_ERROR_IF(log_cond, log...) |
| | Conditionally log an ERROR level message Used for critical errors that may prevent normal operation. Only compiled if UNIOT_LOG_LEVEL is at least UNIOT_LOG_LEVEL_ERROR.
|
| |
| #define | UNIOT_LOG_WARN(...) |
| | Log an WARN level message Used for warnings about potentially problematic situations. Only compiled if UNIOT_LOG_LEVEL is at least UNIOT_LOG_LEVEL_WARN.
|
| |
| #define | UNIOT_LOG_WARN_IF(log_cond, log...) |
| | Conditionally log an WARN level message Used for warnings about potentially problematic situations. Only compiled if UNIOT_LOG_LEVEL is at least UNIOT_LOG_LEVEL_WARN.
|
| |
| #define | UNIOT_LOG_INFO(...) |
| | Log an INFO level message Used for general information about system operation. Only compiled if UNIOT_LOG_LEVEL is at least UNIOT_LOG_LEVEL_INFO.
|
| |
| #define | UNIOT_LOG_INFO_IF(log_cond, log...) |
| | Conditionally log an INFO level message Used for general information about system operation. Only compiled if UNIOT_LOG_LEVEL is at least UNIOT_LOG_LEVEL_INFO.
|
| |
| #define | UNIOT_LOG_DEBUG(...) |
| | Log an DEBUG level message Used for general information about system operation. Only compiled if UNIOT_LOG_LEVEL is at least UNIOT_LOG_LEVEL_DEBUG.
|
| |
| #define | UNIOT_LOG_DEBUG_IF(log_cond, log...) |
| | Conditionally log an DEBUG level message Used for general information about system operation. Only compiled if UNIOT_LOG_LEVEL is at least UNIOT_LOG_LEVEL_DEBUG.
|
| |
| #define | UNIOT_LOG_TRACE(...) |
| | Log an TRACE level message Used for general information about system operation. Only compiled if UNIOT_LOG_LEVEL is at least UNIOT_LOG_LEVEL_TRACE.
|
| |
| #define | UNIOT_LOG_TRACE_IF(log_cond, log...) |
| | Conditionally log an TRACE level message Used for general information about system operation. Only compiled if UNIOT_LOG_LEVEL is at least UNIOT_LOG_LEVEL_TRACE.
|
| |
Logging system for Uniot devices.
This file provides a customizable logging system for Uniot IoT devices. It defines macros for different log levels and provides a consistent logging interface that can be conditionally compiled based on settings.
The logger outputs messages with timestamps, file info, and function names to help with debugging and monitoring device operations.
◆ __FUNC_NAME__
| #define __FUNC_NAME__ __FUNCTION__ |
Cross-platform function name macro.
Defines a cross-compiler compatible way to get the current function name Works with GCC, Clang, and other compilers
◆ UNIOT_LOG
| #define UNIOT_LOG |
( |
| log_type, |
|
|
| log_fmt, |
|
|
| log_arg... ) |
Value: do { \
uniot_log_printf(PSTR("[" #log_type "][%lu][" __FILE__ ":" \
} while (0)
#define __FUNC_NAME__
Cross-platform function name macro.
Definition Logger.h:46
#define UNIOT_LOG_STRINGIFY(x)
Definition Logger.h:165
◆ UNIOT_LOG_BAUD_RATE
| #define UNIOT_LOG_BAUD_RATE 115200 |
Default baud rate for serial logging.
Sets the communication speed for the logging serial port. Can be overridden by defining UNIOT_LOG_BAUD_RATE before including this file.
◆ UNIOT_LOG_BUF_SIZE
| #define UNIOT_LOG_BUF_SIZE 256 |
Maximum size of the logging buffer.
Defines the maximum size of a single log message. Messages longer than this will be truncated with "[...]" indicator.
◆ UNIOT_LOG_DEBUG
| #define UNIOT_LOG_DEBUG |
( |
| ... | ) |
|
Value:
#define UNIOT_LOG(log_type, log_fmt, log_arg...)
Definition Logger.h:171
Log an DEBUG level message Used for general information about system operation. Only compiled if UNIOT_LOG_LEVEL is at least UNIOT_LOG_LEVEL_DEBUG.
- Parameters
-
| ... | Printf-style format string followed by arguments |
◆ UNIOT_LOG_DEBUG_IF
| #define UNIOT_LOG_DEBUG_IF |
( |
| log_cond, |
|
|
| log... ) |
Value:
#define UNIOT_LOG_IF(log_type, log_cond, log_fmt, log_arg...)
Conditional logging macro.
Definition Logger.h:188
Conditionally log an DEBUG level message Used for general information about system operation. Only compiled if UNIOT_LOG_LEVEL is at least UNIOT_LOG_LEVEL_DEBUG.
- Parameters
-
| log_cond | Condition that must be true for the message to be logged |
| log... | Printf-style format string followed by arguments |
◆ UNIOT_LOG_ERROR
| #define UNIOT_LOG_ERROR |
( |
| ... | ) |
|
Value:
Log an ERROR level message Used for critical errors that may prevent normal operation. Only compiled if UNIOT_LOG_LEVEL is at least UNIOT_LOG_LEVEL_ERROR.
- Parameters
-
| ... | Printf-style format string followed by arguments |
◆ UNIOT_LOG_ERROR_IF
| #define UNIOT_LOG_ERROR_IF |
( |
| log_cond, |
|
|
| log... ) |
Value:
Conditionally log an ERROR level message Used for critical errors that may prevent normal operation. Only compiled if UNIOT_LOG_LEVEL is at least UNIOT_LOG_LEVEL_ERROR.
- Parameters
-
| log_cond | Condition that must be true for the message to be logged |
| log... | Printf-style format string followed by arguments |
◆ UNIOT_LOG_IF
| #define UNIOT_LOG_IF |
( |
| log_type, |
|
|
| log_cond, |
|
|
| log_fmt, |
|
|
| log_arg... ) |
Value: do { \
if (log_cond) \
UNIOT_LOG(log_type, log_fmt, ##log_arg); \
} while (0)
Conditional logging macro.
Only outputs a log message if the specified condition is true.
- Parameters
-
| log_type | Type/level of the log message |
| log_cond | Condition that must be true for the message to be logged |
| log_fmt | Format string for the message |
| log_arg | Variable arguments for format string |
◆ UNIOT_LOG_INFO
| #define UNIOT_LOG_INFO |
( |
| ... | ) |
|
Value:
Log an INFO level message Used for general information about system operation. Only compiled if UNIOT_LOG_LEVEL is at least UNIOT_LOG_LEVEL_INFO.
- Parameters
-
| ... | Printf-style format string followed by arguments |
◆ UNIOT_LOG_INFO_IF
| #define UNIOT_LOG_INFO_IF |
( |
| log_cond, |
|
|
| log... ) |
Value:
Conditionally log an INFO level message Used for general information about system operation. Only compiled if UNIOT_LOG_LEVEL is at least UNIOT_LOG_LEVEL_INFO.
- Parameters
-
| log_cond | Condition that must be true for the message to be logged |
| log... | Printf-style format string followed by arguments |
◆ UNIOT_LOG_LEVEL_DEBUG
| #define UNIOT_LOG_LEVEL_DEBUG 3 |
◆ UNIOT_LOG_LEVEL_ERROR
| #define UNIOT_LOG_LEVEL_ERROR 0 |
Log level definitions.
Defines the various logging levels in order of verbosity:
- ERROR: Critical errors that prevent normal operation
- WARN: Warnings that don't stop operation but indicate issues
- INFO: General information about system operation
- DEBUG: Detailed information for debugging purposes
- TRACE: Very detailed tracing information for deep debugging
◆ UNIOT_LOG_LEVEL_INFO
| #define UNIOT_LOG_LEVEL_INFO 2 |
◆ UNIOT_LOG_LEVEL_TRACE
| #define UNIOT_LOG_LEVEL_TRACE 4 |
◆ UNIOT_LOG_LEVEL_WARN
| #define UNIOT_LOG_LEVEL_WARN 1 |
◆ UNIOT_LOG_PRINT
| #define UNIOT_LOG_PRINT |
( |
| ... | ) |
|
Value: do { \
} while (0)
#define UNIOT_LOG_STREAM
Default log level.
Definition Logger.h:97
Print to the logging stream.
Outputs text to the configured logging stream if available. Can be overridden by defining UNIOT_LOG_PRINT before including this file.
◆ UNIOT_LOG_SET_READY
| #define UNIOT_LOG_SET_READY |
( |
| ) |
|
Value: do { \
} \
} while (0)
#define UNIOT_LOG_BAUD_RATE
Default baud rate for serial logging.
Definition Logger.h:107
Initialize the logging system.
Sets up the serial port for logging if not already initialized. Can be overridden by defining UNIOT_LOG_SET_READY before including this file.
◆ UNIOT_LOG_STREAM
| #define UNIOT_LOG_STREAM Serial |
Default log level.
Sets the default logging level if not defined elsewhere. Can be overridden by defining UNIOT_LOG_LEVEL before including this file.
Logging implementation when enabled
When UNIOT_LOG_ENABLED is defined, this section provides the actual implementation of the logging functionality.
Default serial port for logging
Can be overridden by defining UNIOT_LOG_STREAM before including this file.
◆ UNIOT_LOG_STRINGIFY
| #define UNIOT_LOG_STRINGIFY |
( |
| x | ) |
|
Value:
#define UNIOT_LOG_STRINGIFY_(x)
Core logging macro.
Definition Logger.h:164
◆ UNIOT_LOG_STRINGIFY_
| #define UNIOT_LOG_STRINGIFY_ |
( |
| x | ) |
|
Value:
Core logging macro.
Formats and outputs a log message with:
- Log level indicator
- Timestamp (milliseconds)
- File name and line number
- Function name
- User message with printf-style formatting
- Parameters
-
| log_type | Type/level of the log message (ERROR, WARN, etc.) |
| log_fmt | Format string for the message |
| log_arg | Variable arguments for format string |
◆ UNIOT_LOG_TRACE
| #define UNIOT_LOG_TRACE |
( |
| ... | ) |
|
Value:
Log an TRACE level message Used for general information about system operation. Only compiled if UNIOT_LOG_LEVEL is at least UNIOT_LOG_LEVEL_TRACE.
- Parameters
-
| ... | Printf-style format string followed by arguments |
◆ UNIOT_LOG_TRACE_IF
| #define UNIOT_LOG_TRACE_IF |
( |
| log_cond, |
|
|
| log... ) |
Value:
Conditionally log an TRACE level message Used for general information about system operation. Only compiled if UNIOT_LOG_LEVEL is at least UNIOT_LOG_LEVEL_TRACE.
- Parameters
-
| log_cond | Condition that must be true for the message to be logged |
| log... | Printf-style format string followed by arguments |
◆ UNIOT_LOG_WARN
| #define UNIOT_LOG_WARN |
( |
| ... | ) |
|
Value:
Log an WARN level message Used for warnings about potentially problematic situations. Only compiled if UNIOT_LOG_LEVEL is at least UNIOT_LOG_LEVEL_WARN.
- Parameters
-
| ... | Printf-style format string followed by arguments |
◆ UNIOT_LOG_WARN_IF
| #define UNIOT_LOG_WARN_IF |
( |
| log_cond, |
|
|
| log... ) |
Value:
Conditionally log an WARN level message Used for warnings about potentially problematic situations. Only compiled if UNIOT_LOG_LEVEL is at least UNIOT_LOG_LEVEL_WARN.
- Parameters
-
| log_cond | Condition that must be true for the message to be logged |
| log... | Printf-style format string followed by arguments |
◆ uniot_log_sink_t
| typedef void(* uniot_log_sink_t) (const char *msg) |
Log sink function type.
Function pointer called with every formatted log line (including the level prefix, timestamp, file, line, and function name) in addition to the normal Serial output. Set via uniot_log_set_sink().
◆ uniot_log_set_sink()
Register an external log sink.
- Parameters
-
| sink | Function to call for each formatted log line, or nullptr to clear the current sink. |
◆ sUniotLogSink
Global log sink (C++17 inline variable, one copy per program).
Do not write this directly. Use uniot_log_set_sink(). Must be set before any RTOS tasks fire to avoid a write/read race on the pointer itself.