18#ifndef __FPSDK_COMMON_LOGGING_HPP__
19#define __FPSDK_COMMON_LOGGING_HPP__
52#define FATAL(fmt, ...) _FPSDK_LOGGING_LOG(FATAL, "Fatal: " fmt, ## __VA_ARGS__)
56#define ERROR(fmt, ...) _FPSDK_LOGGING_LOG(ERROR, "Error: " fmt, ## __VA_ARGS__)
60#define WARNING(fmt, ...) _FPSDK_LOGGING_LOG(WARNING, "Warning: " fmt, ## __VA_ARGS__)
64#define NOTICE(fmt, ...) _FPSDK_LOGGING_LOG(NOTICE, fmt, ## __VA_ARGS__)
68#define INFO(fmt, ...) _FPSDK_LOGGING_LOG(INFO, fmt, ## __VA_ARGS__)
72#define DEBUG(fmt, ...) _FPSDK_LOGGING_LOG(DEBUG, fmt, ## __VA_ARGS__)
76#define DEBUG_HEXDUMP(data, size, prefix, fmt, ...) _FPSDK_LOGGING_HEX(DEBUG, data, size, prefix, fmt, ## __VA_ARGS__)
77#if !defined(NDEBUG) || defined(_DOXYGEN_)
82# define TRACE(fmt, ...) _FPSDK_LOGGING_LOG(TRACE, fmt, ## __VA_ARGS__)
86# define TRACE_HEXDUMP(data, size, prefix, fmt, ...) _FPSDK_LOGGING_HEX(TRACE, data, size, prefix, fmt, ## __VA_ARGS__)
89# define TRACE_HEXDUMP(...)
95#define ERROR_THR(millis, fmt, ...) _FPSDK_LOGGING_THR(ERROR, millis, fmt, ## __VA_ARGS__)
99#define WARNING_THR(millis, fmt, ...) _FPSDK_LOGGING_THR(WARNING, millis, fmt, ## __VA_ARGS__)
103#define NOTICE_THR(millis, fmt, ...) _FPSDK_LOGGING_THR(NOTICE, millis, fmt, ## __VA_ARGS__)
107#define INFO_THR(millis, fmt, ...) _FPSDK_LOGGING_THR(INFO, millis, fmt, ## __VA_ARGS__)
111#define DEBUG_THR(millis, fmt, ...) _FPSDK_LOGGING_THR(DEBUG, millis, fmt, ## __VA_ARGS__)
126#define FATAL_S(expr) _FPSDK_LOGGING_IF(FATAL, std::stringstream ss; ss << expr; FATAL("%s", ss.str().c_str()))
130#define ERROR_S(expr) _FPSDK_LOGGING_IF(ERROR, std::stringstream ss; ss << expr; ERROR("%s", ss.str().c_str()))
134#define WARNING_S(expr) _FPSDK_LOGGING_IF(WARNING, std::stringstream ss; ss << expr; WARNING("%s", ss.str().c_str()))
138#define DEBUG_S(expr) _FPSDK_LOGGING_IF(DEBUG, std::stringstream ss; ss << expr; DEBUG("%s", ss.str().c_str()))
142#define NOTICE_S(expr) _FPSDK_LOGGING_IF(NOTIC, std::stringstream ss; ss << expr; NOTICE("%s", ss.str().c_str()))
146#define INFO_S(expr) _FPSDK_LOGGING_IF(INFO, std::stringstream ss; ss << expr; INFO("%s", ss.str().c_str()))
148#if !defined(NDEBUG) || defined(_DOXYGEN_)
152# define TRACE_S(expr) _FPSDK_LOGGING_IF(TRACE, std::stringstream ss; ss << expr; TRACE("%s", ss.str().c_str()))
159#if !defined(NDEBUG) || defined(_DOXYGEN_)
161# define IF_TRACE(...) __VA_ARGS__
163# define IF_TRACE(...)
329# define _FPSDK_LOGGING_LOG(_level_, _fmt_, ...) \
330 ::fpsdk::common::logging::LoggingPrint(fpsdk::common::logging::LoggingLevel::_level_, _fmt_, ##__VA_ARGS__)
331# define _FPSDK_LOGGING_HEX(_level_, _data_, _size_, _prefix_, _fmt_, ...) \
332 ::fpsdk::common::logging::LoggingHexdump( \
333 fpsdk::common::logging::LoggingLevel::_level_, _data_, _size_, _prefix_, _fmt_, ##__VA_ARGS__)
334# define _FPSDK_LOGGING_IF(_level_, _code_) \
335 if (::fpsdk::common::logging::LoggingIsLevel(fpsdk::common::logging::LoggingLevel::_level_)) { \
338# define _FPSDK_LOGGING_THR(_level_, _millis_, _fmt_, ...) \
340 static uint32_t __last = 0; \
341 const uint32_t __now = ::fpsdk::common::time::GetMillis(); \
342 if ((__now - __last) >= (_millis_)) { \
344 _level_(_fmt_, ##__VA_ARGS__); \
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.
void LoggingHexdump(const LoggingLevel level, const uint8_t *data, const std::size_t size, const char *prefix, const char *fmt,...) PRINTF_ATTR(5)
Print a hexdump.
const char * LoggingTimestampsStr(const LoggingTimestamps timestamps)
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.
LoggingTimestamps
Logging timestamps.
@ ABSOLUTE
Absolute timestamps (local time, yyyy-mm-dd hh::mm:ss.sss format)
@ RELATIVE
Relative timestamps (since first logging message, sssss.sss format)
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)
const char * LoggingColourStr(const LoggingColour colour)
Stringify log level.
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.
LoggingColour colour_
Level colours.
LoggingLevel level_
Logging level.
LoggingParams(const LoggingLevel level=LoggingLevel::INFO, const LoggingColour colour=LoggingColour::AUTO, const LoggingTimestamps timestamps=LoggingTimestamps::NONE)
Constructor.
LoggingPrintFunc fn_
Custom logging print function.
LoggingTimestamps timestamps_
Timestamps.
Fixposition SDK: Time utilities.