18#ifndef __FPSDK_COMMON_LOGGING_HPP__
19#define __FPSDK_COMMON_LOGGING_HPP__
52#define FATAL(...) _FPSDK_LOGGING_LOG(FATAL, "Fatal: " __VA_ARGS__)
56#define ERROR(...) _FPSDK_LOGGING_LOG(ERROR, "Error: " __VA_ARGS__)
60#define WARNING(...) _FPSDK_LOGGING_LOG(WARNING, "Warning: " __VA_ARGS__)
64#define NOTICE(...) _FPSDK_LOGGING_LOG(NOTICE, __VA_ARGS__)
68#define INFO(...) _FPSDK_LOGGING_LOG(INFO, __VA_ARGS__)
72#define DEBUG(...) _FPSDK_LOGGING_LOG(DEBUG, __VA_ARGS__)
76#define DEBUG_HEXDUMP(data, size, prefix, ...) _FPSDK_LOGGING_HEX(DEBUG, data, size, prefix, __VA_ARGS__)
77#if !defined(NDEBUG) || defined(_DOXYGEN_)
82# define TRACE(...) _FPSDK_LOGGING_LOG(TRACE, __VA_ARGS__)
86# define TRACE_HEXDUMP(data, size, prefix, ...) _FPSDK_LOGGING_HEX(TRACE, data, size, prefix, __VA_ARGS__)
89# define TRACE_HEXDUMP(...)
95#define ERROR_THR(millis, ...) _FPSDK_LOGGING_THR(ERROR, millis, __VA_ARGS__)
99#define WARNING_THR(millis, ...) _FPSDK_LOGGING_THR(WARNING, millis, __VA_ARGS__)
103#define NOTICE_THR(millis, ...) _FPSDK_LOGGING_THR(NOTICE, millis, __VA_ARGS__)
107#define INFO_THR(millis, ...) _FPSDK_LOGGING_THR(INFO, millis, __VA_ARGS__)
111#define DEBUG_THR(millis, ...) _FPSDK_LOGGING_THR(DEBUG, millis, __VA_ARGS__)
126#define FATAL_S(expr) _FPSDK_LOGGING_STR(FATAL, expr)
130#define ERROR_S(expr) _FPSDK_LOGGING_STR(ERROR, expr)
134#define WARNING_S(expr) _FPSDK_LOGGING_STR(WARNING, expr)
138#define DEBUG_S(expr) _FPSDK_LOGGING_STR(DEBUG, expr)
142#define NOTICE_S(expr) _FPSDK_LOGGING_STR(NOTICE, expr)
146#define INFO_S(expr) _FPSDK_LOGGING_STR(INFO, expr)
148#if !defined(NDEBUG) || defined(_DOXYGEN_)
152# define TRACE_S(expr) _FPSDK_LOGGING_STR(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(...)
333# define _FPSDK_LOGGING_LOG(_level_, ...) \
334 ::fpsdk::common::logging::LoggingPrint(::fpsdk::common::logging::LoggingLevel::_level_, 0, __VA_ARGS__)
335# define _FPSDK_LOGGING_HEX(_level_, _data_, _size_, _prefix_, ...) \
336 ::fpsdk::common::logging::LoggingHexdump( \
337 ::fpsdk::common::logging::LoggingLevel::_level_, _data_, _size_, _prefix_, __VA_ARGS__)
338# define _FPSDK_LOGGING_STR(_level_, _expr_) \
339 if (::fpsdk::common::logging::LoggingIsLevel(::fpsdk::common::logging::LoggingLevel::_level_)) { \
340 std::stringstream ss; \
342 ::fpsdk::common::logging::LoggingPrint( \
343 ::fpsdk::common::logging::LoggingLevel::_level_, 0, "%s", ss.str().c_str()); \
345# define _FPSDK_LOGGING_THR(_level_, _millis_, ...) \
347 static uint32_t __last = 0; \
348 static uint32_t __repeat = 0; \
349 const uint32_t __now = ::fpsdk::common::time::GetMillis(); \
351 if ((__now - __last) >= (_millis_)) { \
353 ::fpsdk::common::logging::LoggingPrint( \
354 ::fpsdk::common::logging::LoggingLevel::_level_, __repeat, __VA_ARGS__); \
void LoggingPrint(const LoggingLevel level, const std::size_t repeat, const char *fmt,...) PRINTF_ATTR(3)
Print a log message.
void(*)(const LoggingParams ¶ms, const LoggingLevel level, const char *str) LoggingWriteFunc
Custom logging write (to screen, file, ...) function signature.
LoggingParams LoggingGetParams()
Get current logging params.
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)
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.
LoggingWriteFunc fn_
Custom logging write function.
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.
LoggingTimestamps timestamps_
Timestamps.
Fixposition SDK: Time utilities.