18#ifndef __FPSDK_COMMON_LOGGING_HPP__
19#define __FPSDK_COMMON_LOGGING_HPP__
50#define FATAL(fmt, ...) fpsdk::common::logging::LoggingPrint(fpsdk::common::logging::LoggingLevel::FATAL, "Fatal: " fmt, ## __VA_ARGS__)
54#define ERROR(fmt, ...) fpsdk::common::logging::LoggingPrint(fpsdk::common::logging::LoggingLevel::ERROR, "Error: " fmt, ## __VA_ARGS__)
58#define WARNING(fmt, ...) fpsdk::common::logging::LoggingPrint(fpsdk::common::logging::LoggingLevel::WARNING, "Warning: " fmt, ## __VA_ARGS__)
62#define NOTICE(fmt, ...) fpsdk::common::logging::LoggingPrint(fpsdk::common::logging::LoggingLevel::NOTICE, fmt, ## __VA_ARGS__)
66#define INFO(fmt, ...) fpsdk::common::logging::LoggingPrint(fpsdk::common::logging::LoggingLevel::INFO, fmt, ## __VA_ARGS__)
70#define DEBUG(fmt, ...) fpsdk::common::logging::LoggingPrint(fpsdk::common::logging::LoggingLevel::DEBUG, fmt, ## __VA_ARGS__)
74#define DEBUG_HEXDUMP(data, size, prefix, fmt, ...) fpsdk::common::logging::LoggingHexdump(fpsdk::common::logging::LoggingLevel::DEBUG, data, size, prefix, fmt, ## __VA_ARGS__)
75#if !defined(NDEBUG) || defined(_DOXYGEN_)
79# define TRACE(fmt, ...) fpsdk::common::logging::LoggingPrint(fpsdk::common::logging::LoggingLevel::TRACE, fmt, ## __VA_ARGS__)
83# define TRACE_HEXDUMP(data, size, prefix, fmt, ...) fpsdk::common::logging::LoggingHexdump(fpsdk::common::logging::LoggingLevel::TRACE, data, size, prefix, fmt, ## __VA_ARGS__)
86# define TRACE_HEXDUMP(...)
102#define FATAL_S(expr) if (fpsdk::common::logging::LoggingIsLevel(fpsdk::common::logging::LoggingLevel::FATAL)) { \
103 std::stringstream ss; ss << expr; FATAL("%s", ss.str().c_str()); }
107#define ERROR_S(expr) if (fpsdk::common::logging::LoggingIsLevel(fpsdk::common::logging::LoggingLevel::ERROR)) { \
108 std::stringstream ss; ss << expr; ERROR("%s", ss.str().c_str()); }
112#define WARNING_S(expr) if (fpsdk::common::logging::LoggingIsLevel(fpsdk::common::logging::LoggingLevel::WARNING)) { \
113 std::stringstream ss; ss << expr; WARNING("%s", ss.str().c_str()); }
117#define DEBUG_S(expr) if (fpsdk::common::logging::LoggingIsLevel(fpsdk::common::logging::LoggingLevel::DEBUG)) { \
118 std::stringstream ss; ss << expr; DEBUG("%s", ss.str().c_str()); }
122#define NOTICE_S(expr) if (fpsdk::common::logging::LoggingIsLevel(fpsdk::common::logging::LoggingLevel::NOTICE)) { \
123 std::stringstream ss; ss << expr; NOTICE("%s", ss.str().c_str()); }
127#define INFO_S(expr) if (fpsdk::common::logging::LoggingIsLevel(fpsdk::common::logging::LoggingLevel::INFO)) { \
128 std::stringstream ss; ss << expr; INFO("%s", ss.str().c_str()); }
129#if !defined(NDEBUG) || defined(_DOXYGEN_)
133# define TRACE_S(expr) if (fpsdk::common::logging::LoggingIsLevel(fpsdk::common::logging::LoggingLevel::TRACE)) { \
134 std::stringstream ss; ss << expr; TRACE("%s", ss.str().c_str()); }
void LoggingHexdump(const LoggingLevel level, const uint8_t *data, const uint64_t size, const char *prefix, const char *fmt,...) PRINTF_ATTR(5)
Print a hexdump.
LoggingLevel
Logging verbosity levels, default is INFO.
@ WARNING
[4/warning] Warnings (for libs and apps)
@ FATAL
[2/crit] Hard errors, critical conditions (for apps). Cannot be silenced.
@ TRACE
[7/debug] Extra debugging, only compiled-in in non-Release builds
@ INFO
[6/info] Interesting stuff, the default level (for apps)
@ NOTICE
[5/notice] Significant stuff, for example headings (for apps)
@ ERROR
[3/err] Errors (for apps)
@ DEBUG
[7/debug] Debugging (for libs and apps)
LoggingParams LoggingGetParams()
Get current logging params.
void(*)(const LoggingParams &, const LoggingLevel, const char *) LoggingPrintFunc
Custom logging print function signature.
LoggingParams LoggingSetParams(const LoggingParams ¶ms)
Configure logging.
const char * LoggingLevelStr(const LoggingLevel level)
Stringify log level.
bool LoggingIsLevel(const LoggingLevel level)
Check if given level would print.
LoggingLevel & operator++(LoggingLevel &level)
Increase verbosity (pre-increment)
void LoggingPrint(const LoggingLevel level, const char *fmt,...) PRINTF_ATTR(2)
Print a log message.
LoggingLevel & operator--(LoggingLevel &level)
Decrease verbosity (pre-decrement)
LoggingColour
Logging "colours".
@ JOURNAL
Use systemd journal level indicators (instead of terminal colours), useful for systemd services.
@ YES
Use colours (terminal escape sequences)
@ AUTO
Automatic (default), use colours if stderr is an interactive terminal.
Fixposition SDK: String utilities.
#define PRINTF_ATTR(n)
Helper macro for marking functions as taking printf() style formatting strings.
LoggingParams(const LoggingLevel level=LoggingLevel::INFO, const LoggingColour colour=LoggingColour::AUTO)
Constructor.
LoggingColour colour_
Level colours.
LoggingLevel level_
Logging level.
LoggingPrintFunc fn_
Custom logging print function.