39#ifndef __FPSDK_COMMON_LOGGING_HPP__
40#define __FPSDK_COMMON_LOGGING_HPP__
73#define FATAL(...) _FPSDK_LOGGING_LOG(FATAL, "Fatal: " __VA_ARGS__)
77#define ERROR(...) _FPSDK_LOGGING_LOG(ERROR, "Error: " __VA_ARGS__)
81#define WARNING(...) _FPSDK_LOGGING_LOG(WARNING, "Warning: " __VA_ARGS__)
85#define NOTICE(...) _FPSDK_LOGGING_LOG(NOTICE, __VA_ARGS__)
89#define INFO(...) _FPSDK_LOGGING_LOG(INFO, __VA_ARGS__)
93#define DEBUG(...) _FPSDK_LOGGING_LOG(DEBUG, __VA_ARGS__)
97#define DEBUG_HEXDUMP(data, size, prefix, ...) _FPSDK_LOGGING_HEX(DEBUG, data, size, prefix, __VA_ARGS__)
98#if !defined(NDEBUG) || defined(_DOXYGEN_)
103# define TRACE(...) _FPSDK_LOGGING_LOG(TRACE, __VA_ARGS__)
107# define TRACE_HEXDUMP(data, size, prefix, ...) _FPSDK_LOGGING_HEX(TRACE, data, size, prefix, __VA_ARGS__)
110# define TRACE_HEXDUMP(...)
116#define ERROR_THR(millis, ...) _FPSDK_LOGGING_THR(ERROR, millis, __VA_ARGS__)
120#define WARNING_THR(millis, ...) _FPSDK_LOGGING_THR(WARNING, millis, __VA_ARGS__)
124#define NOTICE_THR(millis, ...) _FPSDK_LOGGING_THR(NOTICE, millis, __VA_ARGS__)
128#define INFO_THR(millis, ...) _FPSDK_LOGGING_THR(INFO, millis, __VA_ARGS__)
132#define DEBUG_THR(millis, ...) _FPSDK_LOGGING_THR(DEBUG, millis, __VA_ARGS__)
147#define FATAL_S(expr) _FPSDK_LOGGING_STR(FATAL, expr)
151#define ERROR_S(expr) _FPSDK_LOGGING_STR(ERROR, expr)
155#define WARNING_S(expr) _FPSDK_LOGGING_STR(WARNING, expr)
159#define DEBUG_S(expr) _FPSDK_LOGGING_STR(DEBUG, expr)
163#define NOTICE_S(expr) _FPSDK_LOGGING_STR(NOTICE, expr)
167#define INFO_S(expr) _FPSDK_LOGGING_STR(INFO, expr)
169#if !defined(NDEBUG) || defined(_DOXYGEN_)
173# define TRACE_S(expr) _FPSDK_LOGGING_STR(TRACE, expr)
180#if !defined(NDEBUG) || defined(_DOXYGEN_)
182# define IF_TRACE(...) __VA_ARGS__
184# define IF_TRACE(...)
364# define _FPSDK_LOGGING_LOG(_level_, ...) \
365 ::fpsdk::common::logging::LoggingPrint(::fpsdk::common::logging::LoggingLevel::_level_, 0, __VA_ARGS__)
366# define _FPSDK_LOGGING_HEX(_level_, _data_, _size_, _prefix_, ...) \
367 ::fpsdk::common::logging::LoggingHexdump( \
368 ::fpsdk::common::logging::LoggingLevel::_level_, _data_, _size_, _prefix_, __VA_ARGS__)
369# define _FPSDK_LOGGING_STR(_level_, _expr_) \
371 if (::fpsdk::common::logging::LoggingIsLevel(::fpsdk::common::logging::LoggingLevel::_level_)) { \
372 std::stringstream ss; \
374 ::fpsdk::common::logging::LoggingPrint( \
375 ::fpsdk::common::logging::LoggingLevel::_level_, 0, "%s", ss.str().c_str()); \
378# define _FPSDK_LOGGING_THR(_level_, _millis_, ...) \
380 static uint32_t __last = 0; \
381 static uint32_t __repeat = 0; \
382 const uint32_t __now = ::fpsdk::common::time::GetMillis(); \
384 if ((__now - __last) >= (_millis_)) { \
386 ::fpsdk::common::logging::LoggingPrint( \
387 ::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.
void LoggingDefaultWriteFn(const LoggingParams ¶ms, const LoggingLevel level, const char *str)
Default logging write function.
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.
void * user_
User data, ignored by fpsdk::logging.
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.