LogIt++
Header-only, macro-first C++ logging library
Loading...
Searching...
No Matches
Logging Macros

A collection of macros for streamlined logging operations. More...

#define LOGIT_FUNCTION   __func__
 
#define LOGIT_ENUM_TO_STR_CASE(value)
 Expands to a case statement returning the stringified enum value.
 
#define LOGIT_LEVEL_TRACE   0
 
#define LOGIT_LEVEL_DEBUG   1
 
#define LOGIT_LEVEL_INFO   2
 
#define LOGIT_LEVEL_WARN   3
 
#define LOGIT_LEVEL_ERROR   4
 
#define LOGIT_LEVEL_FATAL   5
 
#define LOGIT_CONCAT_IMPL(x, y)
 Concatenate two tokens without macro expansion.
 
#define LOGIT_CONCAT(x, y)
 Concatenate two tokens with macro expansion.
 
#define LOGIT_MDC_PUT(key, value)
 
#define LOGIT_MDC_REMOVE(key)
 
#define LOGIT_MDC_CLEAR()
 
#define LOGIT_NDC_PUSH(value)
 
#define LOGIT_NDC_POP()
 
#define LOGIT_NDC_CLEAR()
 
#define LOGIT_NDC_GUARD(value)
 
#define LOGIT_COMPILED_LEVEL   LOGIT_LEVEL_TRACE
 
#define LOGIT_PERROR_TRACE(message)
 
#define LOGIT_PERROR_DEBUG(message)
 
#define LOGIT_PERROR_INFO(message)
 
#define LOGIT_PERROR_WARN(message)
 
#define LOGIT_PERROR_ERROR(message)
 
#define LOGIT_PERROR_FATAL(message)
 
#define LOGIT_WINERR_TRACE(message)
 
#define LOGIT_WINERR_DEBUG(message)
 
#define LOGIT_WINERR_INFO(message)
 
#define LOGIT_WINERR_WARN(message)
 
#define LOGIT_WINERR_ERROR(message)
 
#define LOGIT_WINERR_FATAL(message)
 
#define LOGIT_SYSERR_TRACE(message)
 
#define LOGIT_SYSERR_DEBUG(message)
 
#define LOGIT_SYSERR_INFO(message)
 
#define LOGIT_SYSERR_WARN(message)
 
#define LOGIT_SYSERR_ERROR(message)
 
#define LOGIT_SYSERR_FATAL(message)
 

Detailed Description

A collection of macros for streamlined logging operations.

This group includes macros for logging messages at various levels, adding loggers, managing log settings, and controlling loggers.

Examples
Basic Logging
LOGIT_INFO("This is an informational message");
LOGIT_WARN("This is a warning message");
LOGIT_ERROR("This is an error message");
#define LOGIT_ERROR(...)
#define LOGIT_INFO(...)
#define LOGIT_WARN(...)
Stream-Based Logging
LOGIT_STREAM_INFO() << "Info level stream logging: value=" << 42;
LOGIT_STREAM_TRACE_TO(2) << "Trace to unique logger at index 2";
#define LOGIT_STREAM_INFO()
#define LOGIT_STREAM_TRACE_TO(index)
Conditional Logging
int x = 42;
LOGIT_DEBUG_IF(x > 0, "x is positive: ", x);
#define LOGIT_DEBUG_IF(condition,...)
System Error Logging
Use LOGIT_PERROR_<LEVEL> on POSIX and LOGIT_WINERR_<LEVEL> on Windows to automatically attach decoded system error codes to your message. The cross-platform LOGIT_SYSERR_<LEVEL> macro aliases to the appropriate variant.
int fd = ::open("missing.cfg", O_RDONLY);
if (fd == -1) {
LOGIT_SYSERR_ERROR("Failed to open configuration");
}
#define LOGIT_SYSERR_ERROR(message)
Customise the suffix by overriding configuration macros such as LOGIT_OS_ERROR_JOIN, LOGIT_POSIX_ERROR_PATTERN, or LOGIT_WINDOWS_ERROR_PATTERN before including <logit.hpp>.
Logger Management
LOGIT_SET_LOGGER_ENABLED(1, false); // Disable logger at index 1
LOGIT_INFO("Logger 1 is enabled");
}
#define LOGIT_IS_LOGGER_ENABLED(logger_index)
Checks if a logger is enabled.
#define LOGIT_SET_LOGGER_ENABLED(logger_index, enabled)
Enables or disables a logger.
Task Executor Configuration
Use LOGIT_QUEUE_DROP_NEWEST, LOGIT_QUEUE_DROP_OLDEST, or LOGIT_QUEUE_BLOCK with LOGIT_SET_QUEUE_POLICY.
LOGIT_SET_MAX_QUEUE(64); // Limit queue size
LOGIT_SET_QUEUE_POLICY(LOGIT_QUEUE_DROP_OLDEST); // Drop oldest task when full
#define LOGIT_QUEUE_DROP_OLDEST
Queue policy for dropping the oldest task when the queue is full.
#define LOGIT_SET_QUEUE_POLICY(mode)
Sets the behavior when the queue is full.
#define LOGIT_SET_MAX_QUEUE(size)
Sets the maximum number of queued tasks.

Macro Definition Documentation

◆ LOGIT_COMPILED_LEVEL

#define LOGIT_COMPILED_LEVEL   LOGIT_LEVEL_TRACE

Definition at line 87 of file log_macros.hpp.

◆ LOGIT_CONCAT

#define LOGIT_CONCAT ( x,
y )
Value:
#define LOGIT_CONCAT_IMPL(x, y)
Concatenate two tokens without macro expansion.

Concatenate two tokens with macro expansion.

Parameters
xFirst token.
ySecond token.

Definition at line 51 of file log_macros.hpp.

◆ LOGIT_CONCAT_IMPL

#define LOGIT_CONCAT_IMPL ( x,
y )
Value:
x##y

Concatenate two tokens without macro expansion.

Parameters
xFirst token.
ySecond token.

Definition at line 46 of file log_macros.hpp.

◆ LOGIT_ENUM_TO_STR_CASE

#define LOGIT_ENUM_TO_STR_CASE ( value)
Value:
case value: return #value;

Expands to a case statement returning the stringified enum value.

Parameters
valueThe enum value.

Definition at line 35 of file log_macros.hpp.

◆ LOGIT_FUNCTION

#define LOGIT_FUNCTION   __func__

Definition at line 30 of file log_macros.hpp.

◆ LOGIT_LEVEL_DEBUG

#define LOGIT_LEVEL_DEBUG   1

Definition at line 38 of file log_macros.hpp.

◆ LOGIT_LEVEL_ERROR

#define LOGIT_LEVEL_ERROR   4

Definition at line 41 of file log_macros.hpp.

◆ LOGIT_LEVEL_FATAL

#define LOGIT_LEVEL_FATAL   5

Definition at line 42 of file log_macros.hpp.

◆ LOGIT_LEVEL_INFO

#define LOGIT_LEVEL_INFO   2

Definition at line 39 of file log_macros.hpp.

◆ LOGIT_LEVEL_TRACE

#define LOGIT_LEVEL_TRACE   0

Definition at line 37 of file log_macros.hpp.

◆ LOGIT_LEVEL_WARN

#define LOGIT_LEVEL_WARN   3

Definition at line 40 of file log_macros.hpp.

◆ LOGIT_MDC_CLEAR

#define LOGIT_MDC_CLEAR ( )
Value:
do { } while (0)

Definition at line 64 of file log_macros.hpp.

◆ LOGIT_MDC_PUT

#define LOGIT_MDC_PUT ( key,
value )
Value:
do { } while (0)

Definition at line 62 of file log_macros.hpp.

◆ LOGIT_MDC_REMOVE

#define LOGIT_MDC_REMOVE ( key)
Value:
do { } while (0)

Definition at line 63 of file log_macros.hpp.

◆ LOGIT_NDC_CLEAR

#define LOGIT_NDC_CLEAR ( )
Value:
do { } while (0)

Definition at line 67 of file log_macros.hpp.

◆ LOGIT_NDC_GUARD

#define LOGIT_NDC_GUARD ( value)
Value:
do { } while (0)

Definition at line 68 of file log_macros.hpp.

◆ LOGIT_NDC_POP

#define LOGIT_NDC_POP ( )
Value:
do { } while (0)

Definition at line 66 of file log_macros.hpp.

◆ LOGIT_NDC_PUSH

#define LOGIT_NDC_PUSH ( value)
Value:
do { } while (0)

Definition at line 65 of file log_macros.hpp.

◆ LOGIT_PERROR_DEBUG

#define LOGIT_PERROR_DEBUG ( message)
Value:
LOGIT_DETAIL_PERROR(DEBUG, message)
#define LOGIT_DETAIL_PERROR(level_macro, message)

Definition at line 107 of file log_macros.hpp.

◆ LOGIT_PERROR_ERROR

#define LOGIT_PERROR_ERROR ( message)
Value:
LOGIT_DETAIL_PERROR(ERROR, message)

Definition at line 125 of file log_macros.hpp.

◆ LOGIT_PERROR_FATAL

#define LOGIT_PERROR_FATAL ( message)
Value:
LOGIT_DETAIL_PERROR(FATAL, message)

Definition at line 131 of file log_macros.hpp.

◆ LOGIT_PERROR_INFO

#define LOGIT_PERROR_INFO ( message)
Value:
LOGIT_DETAIL_PERROR(INFO, message)

Definition at line 113 of file log_macros.hpp.

◆ LOGIT_PERROR_TRACE

#define LOGIT_PERROR_TRACE ( message)
Value:
LOGIT_DETAIL_PERROR(TRACE, message)

Definition at line 101 of file log_macros.hpp.

◆ LOGIT_PERROR_WARN

#define LOGIT_PERROR_WARN ( message)
Value:
LOGIT_DETAIL_PERROR(WARN, message)

Definition at line 119 of file log_macros.hpp.

◆ LOGIT_SYSERR_DEBUG

#define LOGIT_SYSERR_DEBUG ( message)
Value:
#define LOGIT_PERROR_DEBUG(message)

Definition at line 194 of file log_macros.hpp.

◆ LOGIT_SYSERR_ERROR

#define LOGIT_SYSERR_ERROR ( message)
Value:
#define LOGIT_PERROR_ERROR(message)

Definition at line 197 of file log_macros.hpp.

◆ LOGIT_SYSERR_FATAL

#define LOGIT_SYSERR_FATAL ( message)
Value:
#define LOGIT_PERROR_FATAL(message)

Definition at line 198 of file log_macros.hpp.

◆ LOGIT_SYSERR_INFO

#define LOGIT_SYSERR_INFO ( message)
Value:
#define LOGIT_PERROR_INFO(message)

Definition at line 195 of file log_macros.hpp.

◆ LOGIT_SYSERR_TRACE

#define LOGIT_SYSERR_TRACE ( message)
Value:
#define LOGIT_PERROR_TRACE(message)

Definition at line 193 of file log_macros.hpp.

◆ LOGIT_SYSERR_WARN

#define LOGIT_SYSERR_WARN ( message)
Value:
#define LOGIT_PERROR_WARN(message)

Definition at line 196 of file log_macros.hpp.

◆ LOGIT_WINERR_DEBUG

#define LOGIT_WINERR_DEBUG ( message)
Value:
do { } while (0)

Definition at line 177 of file log_macros.hpp.

◆ LOGIT_WINERR_ERROR

#define LOGIT_WINERR_ERROR ( message)
Value:
do { } while (0)

Definition at line 180 of file log_macros.hpp.

◆ LOGIT_WINERR_FATAL

#define LOGIT_WINERR_FATAL ( message)
Value:
do { } while (0)

Definition at line 181 of file log_macros.hpp.

◆ LOGIT_WINERR_INFO

#define LOGIT_WINERR_INFO ( message)
Value:
do { } while (0)

Definition at line 178 of file log_macros.hpp.

◆ LOGIT_WINERR_TRACE

#define LOGIT_WINERR_TRACE ( message)
Value:
do { } while (0)

Definition at line 176 of file log_macros.hpp.

◆ LOGIT_WINERR_WARN

#define LOGIT_WINERR_WARN ( message)
Value:
do { } while (0)

Definition at line 179 of file log_macros.hpp.