lucid  0.0.1
Lifting-based Uncertain Control Invariant Dynamics
Loading...
Searching...
No Matches
logging.h File Reference
#include <fmt/core.h>
#include <fmt/ostream.h>
#include <fmt/ranges.h>
#include <spdlog/logger.h>
#include <spdlog/sinks/callback_sink.h>
#include <memory>
#include <string>

Namespaces

namespace  lucid::log
 Collection of logging utilities.
 
namespace  lucid
 Root namespace for the lucid library.
 

Macros

#define OSTREAM_FORMATTER(type)
 Define a fmt formatter for a type using ostream formatting.
 
#define LUCID_FORMAT(message, ...)
 Format a message using fmt::format with variadic arguments (NLOG version).
 
#define LUCID_FORMAT_VECTOR(vector)
 Format an Eigen vector with compact output showing only dimensions.
 
#define LUCID_FORMAT_MATRIX(matrix)
 Format an Eigen matrix with compact output showing only dimensions.
 
#define LUCID_FUNCTION_SIGNATURE   function_signature(__PRETTY_FUNCTION__)
 Extract function name from compiler-provided function signature on GCC/Clang.
 
#define LUCID_OUT_LOGGER   ::lucid::log::get_logger(lucid::log::LoggerType::OUT)
 Get the stdout logger instance.
 
#define LUCID_ERR_LOGGER   ::lucid::log::get_logger(lucid::log::LoggerType::ERR)
 Get the stderr logger instance.
 
#define LUCID_VERBOSITY_TO_LOG_LEVEL(verbosity)
 Convert a lucid verbosity level to the corresponding spdlog level.
 
#define LUCID_LOG_INIT_VERBOSITY(verbosity)
 Initialize the logger with the specified verbosity level.
 
#define LUCID_LOG_MSG(msg)
 Format a log message with function signature prefix.
 
#define LUCID_TRACE(msg)
 Log a trace level message.
 
#define LUCID_TRACE_FMT(msg, ...)
 Log a trace level message with formatted arguments.
 
#define LUCID_DEBUG(msg)
 Log a debug level message.
 
#define LUCID_DEBUG_FMT(msg, ...)
 Log a debug level message with formatted arguments.
 
#define LUCID_INFO(msg)
 Log an info level message.
 
#define LUCID_INFO_FMT(msg, ...)
 Log an info level message with formatted arguments.
 
#define LUCID_WARN(msg)
 Log a warning level message.
 
#define LUCID_WARN_FMT(msg, ...)
 Log a warning level message with formatted arguments.
 
#define LUCID_ERROR(msg)
 Log an error level message.
 
#define LUCID_ERROR_FMT(msg, ...)
 Log an error level message with formatted arguments.
 
#define LUCID_CRITICAL(msg)
 Log a critical level message.
 
#define LUCID_CRITICAL_FMT(msg, ...)
 Log a critical level message with formatted arguments.
 
#define LUCID_TRACE_ENABLED   (LUCID_OUT_LOGGER->should_log(spdlog::level::trace))
 Check if trace level logging is enabled.
 
#define LUCID_DEBUG_ENABLED   (LUCID_OUT_LOGGER->should_log(spdlog::level::debug))
 Check if debug level logging is enabled.
 
#define LUCID_INFO_ENABLED   (LUCID_OUT_LOGGER->should_log(spdlog::level::info))
 Check if info level logging is enabled.
 
#define LUCID_WARN_ENABLED   (LUCID_ERR_LOGGER->should_log(spdlog::level::warn))
 Check if warning level logging is enabled.
 
#define LUCID_ERROR_ENABLED   (LUCID_ERR_LOGGER->should_log(spdlog::level::err))
 Check if error level logging is enabled.
 
#define LUCID_CRITICAL_ENABLED   (LUCID_ERR_LOGGER->should_log(spdlog::level::critical))
 Check if critical level logging is enabled.
 

Enumerations

enum class  lucid::log::LoggerType
 Enum used to differentiate between loggers that output to stdout and stderr.
 

Functions

std::shared_ptr< spdlog::logger > lucid::log::get_logger (LoggerType logger_type)
 Get a logger of the specified type.
 
void lucid::log::set_verbosity_level (spdlog::level::level_enum level)
 Set the verbosity level of the logger.
 
void lucid::log::set_verbosity_level (int level)
 Set the verbosity level of the logger.
 
void lucid::log::set_logger_sink (spdlog::custom_log_callback cb)
 Replace the standard logger sink with a custom callback.
 
void lucid::log::set_logger_sink (std::function< void(std::string)> cb)
 Replace the standard logger sink with a custom callback.
 
void lucid::log::set_pattern (const std::string &format)
 Set the format of the logger.
 
void lucid::log::clear_logger ()
 Clear the logger, removing all loggers and their sinks.
 

Variables

constexpr int LUCID_LOG_OFF_LEVEL = -1
 Verbosity level to disable all logging.
 
constexpr int LUCID_LOG_CRITICAL_LEVEL = 0
 Verbosity level for critical messages only.
 
constexpr int LUCID_LOG_ERROR_LEVEL = 1
 Verbosity level for error and critical messages.
 
constexpr int LUCID_LOG_WARN_LEVEL = 2
 Verbosity level for warning, error and critical messages.
 
constexpr int LUCID_LOG_INFO_LEVEL = 3
 Verbosity level for info, warning, error and critical messages.
 
constexpr int LUCID_LOG_DEBUG_LEVEL = 4
 Verbosity level for debug, info, warning, error and critical messages.
 
constexpr int LUCID_LOG_TRACE_LEVEL = 5
 Verbosity level for all messages including trace.
 

Detailed Description

Author
Room 6.030
Licence:
BSD 3-Clause License

Logging macros. Allows logging with different verbosity levels using spdlog. The verbosity level is an integer between 0 and 5. If set to -1, logging is disabled. It starts at 3 (info).

Macro Definition Documentation

◆ LUCID_CRITICAL

#define LUCID_CRITICAL ( msg)
Value:
#define LUCID_LOG_MSG(msg)
Format a log message with function signature prefix.
Definition logging.h:201
#define LUCID_ERR_LOGGER
Get the stderr logger instance.
Definition logging.h:171

Log a critical level message.

Parameters
msgthe message to log

◆ LUCID_CRITICAL_ENABLED

#define LUCID_CRITICAL_ENABLED   (LUCID_ERR_LOGGER->should_log(spdlog::level::critical))

Check if critical level logging is enabled.

Returns
true if critical logging is enabled, false otherwise

◆ LUCID_CRITICAL_FMT

#define LUCID_CRITICAL_FMT ( msg,
... )
Value:
LUCID_ERR_LOGGER->critical(LUCID_LOG_MSG(msg), __VA_ARGS__)

Log a critical level message with formatted arguments.

Parameters
msgthe format string
...arguments to format into the message

◆ LUCID_DEBUG

#define LUCID_DEBUG ( msg)
Value:
#define LUCID_OUT_LOGGER
Get the stdout logger instance.
Definition logging.h:166

Log a debug level message.

Parameters
msgthe message to log

◆ LUCID_DEBUG_ENABLED

#define LUCID_DEBUG_ENABLED   (LUCID_OUT_LOGGER->should_log(spdlog::level::debug))

Check if debug level logging is enabled.

Returns
true if debug logging is enabled, false otherwise

◆ LUCID_DEBUG_FMT

#define LUCID_DEBUG_FMT ( msg,
... )
Value:
LUCID_OUT_LOGGER->debug(LUCID_LOG_MSG(msg), __VA_ARGS__)

Log a debug level message with formatted arguments.

Parameters
msgthe format string
...arguments to format into the message

◆ LUCID_ERR_LOGGER

#define LUCID_ERR_LOGGER   ::lucid::log::get_logger(lucid::log::LoggerType::ERR)

Get the stderr logger instance.

Returns
shared pointer to the stderr logger

◆ LUCID_ERROR

#define LUCID_ERROR ( msg)
Value:

Log an error level message.

Parameters
msgthe message to log

◆ LUCID_ERROR_ENABLED

#define LUCID_ERROR_ENABLED   (LUCID_ERR_LOGGER->should_log(spdlog::level::err))

Check if error level logging is enabled.

Returns
true if error logging is enabled, false otherwise

◆ LUCID_ERROR_FMT

#define LUCID_ERROR_FMT ( msg,
... )
Value:
LUCID_ERR_LOGGER->error(LUCID_LOG_MSG(msg), __VA_ARGS__)

Log an error level message with formatted arguments.

Parameters
msgthe format string
...arguments to format into the message

◆ LUCID_FORMAT

#define LUCID_FORMAT ( message,
... )
Value:
fmt::format(message, __VA_ARGS__)

Format a message using fmt::format with variadic arguments (NLOG version).

When NLOG is defined, this still provides formatting capability.

Parameters
messageformat string
...arguments to format into the message
Returns
formatted string

◆ LUCID_FORMAT_MATRIX

#define LUCID_FORMAT_MATRIX ( matrix)
Value:
fmt::format("[{}x{}]", (matrix).rows(), (matrix).cols())

Format an Eigen matrix with compact output showing only dimensions.

Parameters
matrixthe Eigen matrix to format
Returns
formatted string with dimensions only

◆ LUCID_FORMAT_VECTOR

#define LUCID_FORMAT_VECTOR ( vector)
Value:
fmt::format("[1x{}]", (vector).size())

Format an Eigen vector with compact output showing only dimensions.

Parameters
vectorthe Eigen vector to format
Returns
formatted string with dimensions only

◆ LUCID_FUNCTION_SIGNATURE

#define LUCID_FUNCTION_SIGNATURE   function_signature(__PRETTY_FUNCTION__)

Extract function name from compiler-provided function signature on GCC/Clang.

Uses PRETTY_FUNCTION which provides more detailed function signatures.

◆ LUCID_INFO

#define LUCID_INFO ( msg)
Value:

Log an info level message.

Parameters
msgthe message to log

◆ LUCID_INFO_ENABLED

#define LUCID_INFO_ENABLED   (LUCID_OUT_LOGGER->should_log(spdlog::level::info))

Check if info level logging is enabled.

Returns
true if info logging is enabled, false otherwise

◆ LUCID_INFO_FMT

#define LUCID_INFO_FMT ( msg,
... )
Value:
LUCID_OUT_LOGGER->info(LUCID_LOG_MSG(msg), __VA_ARGS__)

Log an info level message with formatted arguments.

Parameters
msgthe format string
...arguments to format into the message

◆ LUCID_LOG_INIT_VERBOSITY

#define LUCID_LOG_INIT_VERBOSITY ( verbosity)
Value:
#define LUCID_VERBOSITY_TO_LOG_LEVEL(verbosity)
Convert a lucid verbosity level to the corresponding spdlog level.
Definition logging.h:178
void set_verbosity_level(const spdlog::level::level_enum level)
Set the verbosity level of the logger.
Definition logging.cpp:82

Initialize the logger with the specified verbosity level.

Parameters
verbositythe verbosity level to set (0-5, or -1 for off)

◆ LUCID_LOG_MSG

#define LUCID_LOG_MSG ( msg)
Value:
#define LUCID_FUNCTION_SIGNATURE
Extract function name from compiler-provided function signature on GCC/Clang.
Definition logging.h:159

Format a log message with function signature prefix.

Parameters
msgthe message to format
Returns
formatted message string with function signature prefix

◆ LUCID_OUT_LOGGER

#define LUCID_OUT_LOGGER   ::lucid::log::get_logger(lucid::log::LoggerType::OUT)

Get the stdout logger instance.

Returns
shared pointer to the stdout logger

◆ LUCID_TRACE

#define LUCID_TRACE ( msg)
Value:

Log a trace level message.

Parameters
msgthe message to log

◆ LUCID_TRACE_ENABLED

#define LUCID_TRACE_ENABLED   (LUCID_OUT_LOGGER->should_log(spdlog::level::trace))

Check if trace level logging is enabled.

Returns
true if trace logging is enabled, false otherwise

◆ LUCID_TRACE_FMT

#define LUCID_TRACE_FMT ( msg,
... )
Value:
LUCID_OUT_LOGGER->trace(LUCID_LOG_MSG(msg), __VA_ARGS__)

Log a trace level message with formatted arguments.

Parameters
msgthe format string
...arguments to format into the message

◆ LUCID_VERBOSITY_TO_LOG_LEVEL

#define LUCID_VERBOSITY_TO_LOG_LEVEL ( verbosity)
Value:
((verbosity) == LUCID_LOG_CRITICAL_LEVEL \
? spdlog::level::critical \
: ((verbosity) == LUCID_LOG_ERROR_LEVEL \
? spdlog::level::err \
: ((verbosity) == LUCID_LOG_WARN_LEVEL \
? spdlog::level::warn \
: ((verbosity) == LUCID_LOG_INFO_LEVEL \
? spdlog::level::info \
: ((verbosity) == LUCID_LOG_DEBUG_LEVEL \
? spdlog::level::debug \
: ((verbosity) == LUCID_LOG_TRACE_LEVEL ? spdlog::level::trace \
: spdlog::level::off))))))
constexpr int LUCID_LOG_ERROR_LEVEL
Verbosity level for error and critical messages.
Definition logging.h:20
constexpr int LUCID_LOG_TRACE_LEVEL
Verbosity level for all messages including trace.
Definition logging.h:24
constexpr int LUCID_LOG_INFO_LEVEL
Verbosity level for info, warning, error and critical messages.
Definition logging.h:22
constexpr int LUCID_LOG_CRITICAL_LEVEL
Verbosity level for critical messages only.
Definition logging.h:19
constexpr int LUCID_LOG_WARN_LEVEL
Verbosity level for warning, error and critical messages.
Definition logging.h:21
constexpr int LUCID_LOG_DEBUG_LEVEL
Verbosity level for debug, info, warning, error and critical messages.
Definition logging.h:23

Convert a lucid verbosity level to the corresponding spdlog level.

Parameters
verbositythe lucid verbosity level (0-5, or -1 for off)
Returns
corresponding spdlog::level::level_enum value

◆ LUCID_WARN

#define LUCID_WARN ( msg)
Value:

Log a warning level message.

Parameters
msgthe message to log

◆ LUCID_WARN_ENABLED

#define LUCID_WARN_ENABLED   (LUCID_ERR_LOGGER->should_log(spdlog::level::warn))

Check if warning level logging is enabled.

Returns
true if warning logging is enabled, false otherwise

◆ LUCID_WARN_FMT

#define LUCID_WARN_FMT ( msg,
... )
Value:
LUCID_ERR_LOGGER->warn(LUCID_LOG_MSG(msg), __VA_ARGS__)

Log a warning level message with formatted arguments.

Parameters
msgthe format string
...arguments to format into the message

◆ OSTREAM_FORMATTER

#define OSTREAM_FORMATTER ( type)
Value:
template <> \
struct fmt::formatter<type> : ostream_formatter {};

Define a fmt formatter for a type using ostream formatting.

This macro creates a formatter specialization that uses the type's stream operator.

Parameters
typethe type to create a formatter for