Uniot Core
0.8.1
Loading...
Searching...
No Matches
Logger

Logging system for Uniot devices. More...

Macros

#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(log_type, log_fmt, log_arg...)
 Core logging macro.
 
#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.
 

Detailed Description

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.

Macro Definition Documentation

◆ __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("[" #log_type "][%lu][%s:%d][%s] " log_fmt "\n", \
millis(), __FILE__, __LINE__, __FUNC_NAME__, ##log_arg); \
} while (0)
#define __FUNC_NAME__
Cross-platform function name macro.
Definition Logger.h:46

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_typeType/level of the log message (ERROR, WARN, etc.)
log_fmtFormat string for the message
log_argVariable arguments for format string

◆ 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:
UNIOT_LOG(DEBUG, __VA_ARGS__)
#define UNIOT_LOG(log_type, log_fmt, log_arg...)
Core logging macro.
Definition Logger.h:159

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:
UNIOT_LOG_IF(DEBUG, log_cond, ##log)
#define UNIOT_LOG_IF(log_type, log_cond, log_fmt, log_arg...)
Conditional logging macro.
Definition Logger.h:175

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_condCondition 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:
UNIOT_LOG(ERROR, __VA_ARGS__)

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:
UNIOT_LOG_IF(ERROR, 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.

Parameters
log_condCondition 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_typeType/level of the log message
log_condCondition that must be true for the message to be logged
log_fmtFormat string for the message
log_argVariable arguments for format string

◆ UNIOT_LOG_INFO

#define UNIOT_LOG_INFO ( ...)
Value:
UNIOT_LOG(INFO, __VA_ARGS__)

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:
UNIOT_LOG_IF(INFO, 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.

Parameters
log_condCondition 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 { \
UNIOT_LOG_STREAM.print(__VA_ARGS__); \
} while (0)
#define UNIOT_LOG_STREAM
Default log level.
Definition Logger.h:92

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 { \
if (!UNIOT_LOG_STREAM) { \
UNIOT_LOG_STREAM.print("\n\n"); \
} \
} while (0)
#define UNIOT_LOG_BAUD_RATE
Default baud rate for serial logging.
Definition Logger.h:102

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_TRACE

#define UNIOT_LOG_TRACE ( ...)
Value:
UNIOT_LOG(TRACE, __VA_ARGS__)

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:
UNIOT_LOG_IF(TRACE, 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.

Parameters
log_condCondition 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:
UNIOT_LOG(WARN, __VA_ARGS__)

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:
UNIOT_LOG_IF(WARN, 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.

Parameters
log_condCondition that must be true for the message to be logged
log...Printf-style format string followed by arguments