Common System 0.2.0
Common interfaces and patterns for system integration
Loading...
Searching...
No Matches
log_macros.h File Reference

Unified logging macros for convenient logging across all subsystems. More...

#include "log_functions.h"
Include dependency graph for log_macros.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define KCENON_LOG_ARG_COUNT(...)
 Helper macros for variadic argument dispatch.
 
#define KCENON_LOG_ARG_COUNT_IMPL(_1, _2, N, ...)
 
#define KCENON_LOG_PASTE(a, b)
 
#define KCENON_LOG_PASTE_IMPL(a, b)
 
#define KCENON_LOG_DISPATCH(LEVEL, ...)
 
#define LOG_TRACE(...)
 Log a trace-level message.
 
#define LOG_TRACE_1(msg)
 
#define LOG_TRACE_2(logger_name, msg)
 
#define LOG_DEBUG(...)
 Log a debug-level message.
 
#define LOG_DEBUG_1(msg)
 
#define LOG_DEBUG_2(logger_name, msg)
 
#define LOG_INFO(...)
 Log an info-level message.
 
#define LOG_INFO_1(msg)
 
#define LOG_INFO_2(logger_name, msg)
 
#define LOG_WARNING(...)
 Log a warning-level message.
 
#define LOG_WARNING_1(msg)
 
#define LOG_WARNING_2(logger_name, msg)
 
#define LOG_ERROR(...)
 Log an error-level message.
 
#define LOG_ERROR_1(msg)
 
#define LOG_ERROR_2(logger_name, msg)
 
#define LOG_CRITICAL(...)
 Log a critical-level message.
 
#define LOG_CRITICAL_1(msg)
 
#define LOG_CRITICAL_2(logger_name, msg)
 
#define LOG_IF(level, msg)
 Log a message only if the specified level is enabled.
 
#define LOG_IF_TO(level, logger_name, msg)
 Log a message to a named logger only if the level is enabled.
 
#define LOG_FLUSH()
 Flush the default logger's buffer.
 
#define LOG_FLUSH_TO(logger_name)
 Flush a named logger's buffer.
 
#define LOG_IS_ENABLED(level)
 Check if a log level is enabled for the default logger.
 
#define LOG_IS_ENABLED_FOR(level, logger_name)
 Check if a log level is enabled for a named logger.
 
#define KCENON_MIN_LOG_LEVEL   0
 Minimum log level at compile time.
 

Detailed Description

Unified logging macros for convenient logging across all subsystems.

This header provides preprocessor macros that wrap the logging functions from log_functions.h. These macros offer a convenient, concise way to log messages while automatically capturing source location information.

The macros support:

  • Standard LOG_* macros for each log level
  • Conditional logging based on log level

Thread Safety:

  • All macros are thread-safe as they delegate to thread-safe functions.

Usage:

// Basic logging
LOG_INFO("Application started");
LOG_DEBUG("Processing item: " + std::to_string(id));
// Conditional logging (avoids message construction when disabled)
LOG_IF(log_level::debug, expensive_to_string(data));
#define LOG_INFO(...)
Log an info-level message.
Definition log_macros.h:116
#define LOG_DEBUG(...)
Log a debug-level message.
Definition log_macros.h:99
#define LOG_IF(level, msg)
Log a message only if the specified level is enabled.
Definition log_macros.h:193
Note
Prefer using LOG_* macros over direct function calls for consistency.
See also
Issue #175 for implementation requirements.
log_functions.h for the underlying function implementations.

Definition in file log_macros.h.

Macro Definition Documentation

◆ KCENON_LOG_ARG_COUNT

#define KCENON_LOG_ARG_COUNT ( ...)
Value:
KCENON_LOG_ARG_COUNT_IMPL(__VA_ARGS__, 2, 1)
#define KCENON_LOG_ARG_COUNT_IMPL(_1, _2, N,...)
Definition log_macros.h:57

Helper macros for variadic argument dispatch.

These macros enable LOG_* macros to accept either 1 or 2 arguments:

Implementation uses argument counting and token pasting for dispatch.

Definition at line 55 of file log_macros.h.

55#define KCENON_LOG_ARG_COUNT(...) \
56 KCENON_LOG_ARG_COUNT_IMPL(__VA_ARGS__, 2, 1)

◆ KCENON_LOG_ARG_COUNT_IMPL

#define KCENON_LOG_ARG_COUNT_IMPL ( _1,
_2,
N,
... )
Value:
N

Definition at line 57 of file log_macros.h.

◆ KCENON_LOG_DISPATCH

#define KCENON_LOG_DISPATCH ( LEVEL,
... )
Value:
KCENON_LOG_PASTE(LEVEL##_, KCENON_LOG_ARG_COUNT(__VA_ARGS__))(__VA_ARGS__)
#define KCENON_LOG_ARG_COUNT(...)
Helper macros for variadic argument dispatch.
Definition log_macros.h:55
#define KCENON_LOG_PASTE(a, b)
Definition log_macros.h:60

Definition at line 64 of file log_macros.h.

64#define KCENON_LOG_DISPATCH(LEVEL, ...) \
65 KCENON_LOG_PASTE(LEVEL##_, KCENON_LOG_ARG_COUNT(__VA_ARGS__))(__VA_ARGS__)

◆ KCENON_LOG_PASTE

#define KCENON_LOG_PASTE ( a,
b )
Value:
#define KCENON_LOG_PASTE_IMPL(a, b)
Definition log_macros.h:61

Definition at line 60 of file log_macros.h.

◆ KCENON_LOG_PASTE_IMPL

#define KCENON_LOG_PASTE_IMPL ( a,
b )
Value:
a##b

Definition at line 61 of file log_macros.h.

◆ KCENON_MIN_LOG_LEVEL

#define KCENON_MIN_LOG_LEVEL   0

Minimum log level at compile time.

Define this macro before including log_macros.h to disable lower log levels at compile time. This removes the logging calls entirely from the compiled code.

Values:

  • 0: trace (default, all levels enabled)
  • 1: debug
  • 2: info
  • 3: warning
  • 4: error
  • 5: critical
  • 6: off (all logging disabled)

Usage:

#define KCENON_MIN_LOG_LEVEL 2 // Disable trace and debug in release
Unified logging macros for convenient logging across all subsystems.

Definition at line 281 of file log_macros.h.

◆ LOG_CRITICAL

#define LOG_CRITICAL ( ...)
Value:
#define KCENON_LOG_DISPATCH(LEVEL,...)
Definition log_macros.h:64
#define LOG_CRITICAL(...)
Log a critical-level message.
Definition log_macros.h:167

Log a critical-level message.

Supports two forms:

Parameters
msgThe message to log (string or string_view compatible)
logger_name(optional) The name of the logger

Definition at line 167 of file log_macros.h.

◆ LOG_CRITICAL_1

#define LOG_CRITICAL_1 ( msg)
Value:
VoidResult log_critical(std::string_view message, const source_location &loc=source_location::current())
Log a critical-level message.

Definition at line 168 of file log_macros.h.

168#define LOG_CRITICAL_1(msg) \
169 ::kcenon::common::logging::log_critical(msg)

◆ LOG_CRITICAL_2

#define LOG_CRITICAL_2 ( logger_name,
msg )
Value:
VoidResult log_critical_to(const std::string &logger_name, std::string_view message, const source_location &loc=source_location::current())
Log a critical-level message to a named logger.

Definition at line 170 of file log_macros.h.

170#define LOG_CRITICAL_2(logger_name, msg) \
171 ::kcenon::common::logging::log_critical_to(logger_name, msg)

◆ LOG_DEBUG

#define LOG_DEBUG ( ...)
Value:

Log a debug-level message.

Supports two forms:

Parameters
msgThe message to log (string or string_view compatible)
logger_name(optional) The name of the logger

Definition at line 99 of file log_macros.h.

◆ LOG_DEBUG_1

#define LOG_DEBUG_1 ( msg)
Value:
VoidResult log_debug(std::string_view message, const source_location &loc=source_location::current())
Log a debug-level message.

Definition at line 100 of file log_macros.h.

100#define LOG_DEBUG_1(msg) \
101 ::kcenon::common::logging::log_debug(msg)

◆ LOG_DEBUG_2

#define LOG_DEBUG_2 ( logger_name,
msg )
Value:
VoidResult log_debug_to(const std::string &logger_name, std::string_view message, const source_location &loc=source_location::current())
Log a debug-level message to a named logger.

Definition at line 102 of file log_macros.h.

102#define LOG_DEBUG_2(logger_name, msg) \
103 ::kcenon::common::logging::log_debug_to(logger_name, msg)

◆ LOG_ERROR

#define LOG_ERROR ( ...)
Value:
#define LOG_ERROR(...)
Log an error-level message.
Definition log_macros.h:150

Log an error-level message.

Supports two forms:

Parameters
msgThe message to log (string or string_view compatible)
logger_name(optional) The name of the logger

Definition at line 150 of file log_macros.h.

◆ LOG_ERROR_1

#define LOG_ERROR_1 ( msg)
Value:
VoidResult log_error(std::string_view message, const source_location &loc=source_location::current())
Log an error-level message.

Definition at line 151 of file log_macros.h.

151#define LOG_ERROR_1(msg) \
152 ::kcenon::common::logging::log_error(msg)

◆ LOG_ERROR_2

#define LOG_ERROR_2 ( logger_name,
msg )
Value:
VoidResult log_error_to(const std::string &logger_name, std::string_view message, const source_location &loc=source_location::current())
Log an error-level message to a named logger.

Definition at line 153 of file log_macros.h.

153#define LOG_ERROR_2(logger_name, msg) \
154 ::kcenon::common::logging::log_error_to(logger_name, msg)

◆ LOG_FLUSH

#define LOG_FLUSH ( )
Value:
VoidResult flush()
Flush all buffered log messages for the default logger.

Flush the default logger's buffer.

Definition at line 223 of file log_macros.h.

223#define LOG_FLUSH() \
224 ::kcenon::common::logging::flush()

◆ LOG_FLUSH_TO

#define LOG_FLUSH_TO ( logger_name)
Value:

Flush a named logger's buffer.

Parameters
logger_nameThe name of the logger

Definition at line 231 of file log_macros.h.

231#define LOG_FLUSH_TO(logger_name) \
232 ::kcenon::common::logging::flush(logger_name)

◆ LOG_IF

#define LOG_IF ( level,
msg )
Value:
do { \
::kcenon::common::logging::log(level, msg); \
} \
} while (0)
bool is_enabled(interfaces::log_level level)
Check if a log level is enabled for the default logger.

Log a message only if the specified level is enabled.

This macro checks if the log level is enabled before evaluating the message expression, which is useful for avoiding expensive message construction when logging is disabled.

Parameters
levelLog level (e.g., log_level::debug)
msgThe message to log

Usage:

LOG_IF(log_level::debug, "Expensive data: " + expensive_to_string(data));

Definition at line 193 of file log_macros.h.

193#define LOG_IF(level, msg) \
194 do { \
195 if (::kcenon::common::logging::is_enabled(level)) { \
196 ::kcenon::common::logging::log(level, msg); \
197 } \
198 } while (0)

◆ LOG_IF_TO

#define LOG_IF_TO ( level,
logger_name,
msg )
Value:
do { \
if (::kcenon::common::logging::is_enabled(level, logger_name)) { \
::kcenon::common::logging::log(level, msg, logger_name); \
} \
} while (0)

Log a message to a named logger only if the level is enabled.

Parameters
levelLog level (e.g., log_level::debug)
logger_nameThe name of the logger
msgThe message to log

Definition at line 208 of file log_macros.h.

208#define LOG_IF_TO(level, logger_name, msg) \
209 do { \
210 if (::kcenon::common::logging::is_enabled(level, logger_name)) { \
211 ::kcenon::common::logging::log(level, msg, logger_name); \
212 } \
213 } while (0)

◆ LOG_INFO

#define LOG_INFO ( ...)
Value:

Log an info-level message.

Supports two forms:

Parameters
msgThe message to log (string or string_view compatible)
logger_name(optional) The name of the logger

Definition at line 116 of file log_macros.h.

◆ LOG_INFO_1

#define LOG_INFO_1 ( msg)
Value:
VoidResult log_info(std::string_view message, const source_location &loc=source_location::current())
Log an info-level message.

Definition at line 117 of file log_macros.h.

117#define LOG_INFO_1(msg) \
118 ::kcenon::common::logging::log_info(msg)

◆ LOG_INFO_2

#define LOG_INFO_2 ( logger_name,
msg )
Value:
VoidResult log_info_to(const std::string &logger_name, std::string_view message, const source_location &loc=source_location::current())
Log an info-level message to a named logger.

Definition at line 119 of file log_macros.h.

119#define LOG_INFO_2(logger_name, msg) \
120 ::kcenon::common::logging::log_info_to(logger_name, msg)

◆ LOG_IS_ENABLED

#define LOG_IS_ENABLED ( level)
Value:

Check if a log level is enabled for the default logger.

Parameters
levelLog level to check
Returns
true if the level is enabled

Definition at line 240 of file log_macros.h.

240#define LOG_IS_ENABLED(level) \
241 ::kcenon::common::logging::is_enabled(level)

◆ LOG_IS_ENABLED_FOR

#define LOG_IS_ENABLED_FOR ( level,
logger_name )
Value:

Check if a log level is enabled for a named logger.

Parameters
levelLog level to check
logger_nameThe name of the logger
Returns
true if the level is enabled

Definition at line 250 of file log_macros.h.

250#define LOG_IS_ENABLED_FOR(level, logger_name) \
251 ::kcenon::common::logging::is_enabled(level, logger_name)

◆ LOG_TRACE

#define LOG_TRACE ( ...)
Value:
#define LOG_TRACE(...)
Log a trace-level message.
Definition log_macros.h:82

Log a trace-level message.

Supports two forms:

Parameters
msgThe message to log (string or string_view compatible)
logger_name(optional) The name of the logger

Definition at line 82 of file log_macros.h.

◆ LOG_TRACE_1

#define LOG_TRACE_1 ( msg)
Value:
VoidResult log_trace(std::string_view message, const source_location &loc=source_location::current())
Log a trace-level message.

Definition at line 83 of file log_macros.h.

83#define LOG_TRACE_1(msg) \
84 ::kcenon::common::logging::log_trace(msg)

◆ LOG_TRACE_2

#define LOG_TRACE_2 ( logger_name,
msg )
Value:
VoidResult log_trace_to(const std::string &logger_name, std::string_view message, const source_location &loc=source_location::current())
Log a trace-level message to a named logger.

Definition at line 85 of file log_macros.h.

85#define LOG_TRACE_2(logger_name, msg) \
86 ::kcenon::common::logging::log_trace_to(logger_name, msg)

◆ LOG_WARNING

#define LOG_WARNING ( ...)
Value:
#define LOG_WARNING(...)
Log a warning-level message.
Definition log_macros.h:133

Log a warning-level message.

Supports two forms:

Parameters
msgThe message to log (string or string_view compatible)
logger_name(optional) The name of the logger

Definition at line 133 of file log_macros.h.

◆ LOG_WARNING_1

#define LOG_WARNING_1 ( msg)
Value:
VoidResult log_warning(std::string_view message, const source_location &loc=source_location::current())
Log a warning-level message.

Definition at line 134 of file log_macros.h.

134#define LOG_WARNING_1(msg) \
135 ::kcenon::common::logging::log_warning(msg)

◆ LOG_WARNING_2

#define LOG_WARNING_2 ( logger_name,
msg )
Value:
VoidResult log_warning_to(const std::string &logger_name, std::string_view message, const source_location &loc=source_location::current())
Log a warning-level message to a named logger.

Definition at line 136 of file log_macros.h.

136#define LOG_WARNING_2(logger_name, msg) \
137 ::kcenon::common::logging::log_warning_to(logger_name, msg)