2022-01-20 18:27:56 +00:00
|
|
|
// This file Copyright © 2010-2022 Mnemosyne LLC.
|
|
|
|
// It may be used under GPLv2 (SPDX: GPL-2.0), GPLv3 (SPDX: GPL-3.0),
|
|
|
|
// or any future license endorsed by Mnemosyne LLC.
|
|
|
|
// License text can be found in the licenses/ folder.
|
2013-01-25 23:34:20 +00:00
|
|
|
|
2016-03-29 16:37:21 +00:00
|
|
|
#pragma once
|
2013-01-25 23:34:20 +00:00
|
|
|
|
2022-03-11 21:09:22 +00:00
|
|
|
#include <string_view>
|
2014-09-21 18:01:36 +00:00
|
|
|
|
2022-03-10 05:51:14 +00:00
|
|
|
#include "transmission.h"
|
2013-01-25 23:34:20 +00:00
|
|
|
|
|
|
|
#define TR_LOG_MAX_QUEUE_LENGTH 10000
|
|
|
|
|
2022-03-11 21:09:22 +00:00
|
|
|
[[nodiscard]] tr_log_level tr_logGetLevel(void);
|
2013-01-25 23:34:20 +00:00
|
|
|
|
2022-03-11 21:09:22 +00:00
|
|
|
[[nodiscard]] static inline bool tr_logLevelIsActive(tr_log_level level)
|
2013-01-25 23:34:20 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
return tr_logGetLevel() >= level;
|
2013-01-25 23:34:20 +00:00
|
|
|
}
|
|
|
|
|
2022-03-14 04:43:35 +00:00
|
|
|
void tr_logAddMessage(char const* file, int line, tr_log_level level, std::string_view name, std::string_view msg);
|
|
|
|
|
2022-03-11 21:09:22 +00:00
|
|
|
void tr_logAddMessage(char const* file, int line, tr_log_level level, std::string_view name, char const* fmt, ...)
|
2017-04-19 12:04:45 +00:00
|
|
|
TR_GNUC_PRINTF(5, 6);
|
2013-01-25 23:34:20 +00:00
|
|
|
|
2017-05-22 20:12:57 +00:00
|
|
|
#define tr_logAddNamed(level, name, ...) \
|
2017-04-19 12:04:45 +00:00
|
|
|
do \
|
2013-01-25 23:34:20 +00:00
|
|
|
{ \
|
2022-03-11 21:09:22 +00:00
|
|
|
if (tr_logGetLevel() >= level) \
|
2017-04-19 12:04:45 +00:00
|
|
|
{ \
|
2017-05-22 20:12:57 +00:00
|
|
|
tr_logAddMessage(__FILE__, __LINE__, level, name, __VA_ARGS__); \
|
2017-04-19 12:04:45 +00:00
|
|
|
} \
|
2021-08-15 09:41:48 +00:00
|
|
|
} while (0)
|
2013-01-25 23:34:20 +00:00
|
|
|
|
2022-03-11 21:09:22 +00:00
|
|
|
#define tr_logAddNamedCritical(name, ...) tr_logAddNamed(TR_LOG_CRITICAL, (name), __VA_ARGS__)
|
|
|
|
#define tr_logAddNamedError(name, ...) tr_logAddNamed(TR_LOG_ERROR, (name), __VA_ARGS__)
|
|
|
|
#define tr_logAddNamedWarn(name, ...) tr_logAddNamed(TR_LOG_WARN, (name), __VA_ARGS__)
|
|
|
|
#define tr_logAddNamedInfo(name, ...) tr_logAddNamed(TR_LOG_INFO, (name), __VA_ARGS__)
|
|
|
|
#define tr_logAddNamedDebug(name, ...) tr_logAddNamed(TR_LOG_DEBUG, (name), __VA_ARGS__)
|
|
|
|
#define tr_logAddNamedTrace(name, ...) tr_logAddNamed(TR_LOG_TRACE, (name), __VA_ARGS__)
|
2013-01-25 23:34:20 +00:00
|
|
|
|
2022-03-11 21:09:22 +00:00
|
|
|
#define tr_logAddCritical(...) tr_logAddNamed(TR_LOG_CRITICAL, "", __VA_ARGS__)
|
|
|
|
#define tr_logAddError(...) tr_logAddNamed(TR_LOG_ERROR, "", __VA_ARGS__)
|
|
|
|
#define tr_logAddWarn(...) tr_logAddNamed(TR_LOG_WARN, "", __VA_ARGS__)
|
|
|
|
#define tr_logAddInfo(...) tr_logAddNamed(TR_LOG_INFO, "", __VA_ARGS__)
|
|
|
|
#define tr_logAddDebug(...) tr_logAddNamed(TR_LOG_DEBUG, "", __VA_ARGS__)
|
|
|
|
#define tr_logAddTrace(...) tr_logAddNamed(TR_LOG_TRACE, "", __VA_ARGS__)
|
2013-01-25 23:34:20 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
char* tr_logGetTimeStr(char* buf, size_t buflen) TR_GNUC_NONNULL(1);
|
2013-01-25 23:34:20 +00:00
|
|
|
|
|
|
|
/** @} */
|