2013-01-25 23:34:20 +00:00
|
|
|
/*
|
2014-01-18 20:56:57 +00:00
|
|
|
* This file Copyright (C) 2010-2014 Mnemosyne LLC
|
2013-01-25 23:34:20 +00:00
|
|
|
*
|
2014-01-21 03:10:30 +00:00
|
|
|
* It may be used under the GNU GPL versions 2 or 3
|
2014-01-19 01:09:44 +00:00
|
|
|
* or any future license endorsed by Mnemosyne LLC.
|
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
|
|
|
|
|
|
|
#include <stddef.h> /* size_t */
|
2014-09-21 18:01:36 +00:00
|
|
|
|
|
|
|
#include "file.h" /* tr_sys_file_t */
|
2013-01-25 23:34:20 +00:00
|
|
|
#include "utils.h" /* TR_GNUC_PRINTF, TR_GNUC_NONNULL */
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
2017-04-19 12:04:45 +00:00
|
|
|
extern "C"
|
|
|
|
{
|
2013-01-25 23:34:20 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define TR_LOG_MAX_QUEUE_LENGTH 10000
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_log_level tr_logGetLevel(void);
|
2013-01-25 23:34:20 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-02-10 11:05:16 +00:00
|
|
|
void tr_logAddMessage(char const* file, int line, tr_log_level level, char const* torrent, 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
|
|
|
{ \
|
2017-05-22 20:12:57 +00:00
|
|
|
if (tr_logLevelIsActive(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
|
|
|
} \
|
2013-01-25 23:34:20 +00:00
|
|
|
} \
|
2017-04-19 12:04:45 +00:00
|
|
|
while (0)
|
2013-01-25 23:34:20 +00:00
|
|
|
|
2017-05-22 20:12:57 +00:00
|
|
|
#define tr_logAddNamedError(name, ...) tr_logAddNamed(TR_LOG_ERROR, name, __VA_ARGS__)
|
|
|
|
#define tr_logAddNamedInfo(name, ...) tr_logAddNamed(TR_LOG_INFO, name, __VA_ARGS__)
|
|
|
|
#define tr_logAddNamedDbg(name, ...) tr_logAddNamed(TR_LOG_DEBUG, name, __VA_ARGS__)
|
2013-01-25 23:34:20 +00:00
|
|
|
|
2017-05-22 20:12:57 +00:00
|
|
|
#define tr_logAddTor(level, tor, ...) tr_logAddNamed(level, tr_torrentName(tor), __VA_ARGS__)
|
2013-01-25 23:34:20 +00:00
|
|
|
|
2017-05-22 20:12:57 +00:00
|
|
|
#define tr_logAddTorErr(tor, ...) tr_logAddTor(TR_LOG_ERROR, tor, __VA_ARGS__)
|
|
|
|
#define tr_logAddTorInfo(tor, ...) tr_logAddTor(TR_LOG_INFO, tor, __VA_ARGS__)
|
|
|
|
#define tr_logAddTorDbg(tor, ...) tr_logAddTor(TR_LOG_DEBUG, tor, __VA_ARGS__)
|
2013-01-25 23:34:20 +00:00
|
|
|
|
2017-05-22 20:12:57 +00:00
|
|
|
#define tr_logAdd(level, ...) tr_logAddNamed(level, NULL, __VA_ARGS__)
|
2013-01-25 23:34:20 +00:00
|
|
|
|
2017-05-22 20:12:57 +00:00
|
|
|
#define tr_logAddError(...) tr_logAdd(TR_LOG_ERROR, __VA_ARGS__)
|
|
|
|
#define tr_logAddInfo(...) tr_logAdd(TR_LOG_INFO, __VA_ARGS__)
|
|
|
|
#define tr_logAddDebug(...) tr_logAdd(TR_LOG_DEBUG, __VA_ARGS__)
|
2013-01-25 23:34:20 +00:00
|
|
|
|
2017-05-22 20:12:57 +00:00
|
|
|
tr_sys_file_t tr_logGetFile(void);
|
2013-01-25 23:34:20 +00:00
|
|
|
|
2017-05-22 20:12:57 +00:00
|
|
|
/** @brief return true if deep logging has been enabled by the user; false otherwise */
|
|
|
|
bool tr_logGetDeepEnabled(void);
|
2013-01-25 23:34:20 +00:00
|
|
|
|
2019-02-10 11:05:16 +00:00
|
|
|
void tr_logAddDeep(char const* file, int line, char const* name, char const* fmt, ...) TR_GNUC_PRINTF(4, 5) \
|
2017-05-22 20:12:57 +00:00
|
|
|
TR_GNUC_NONNULL(1, 4);
|
|
|
|
|
|
|
|
#define tr_logAddDeepNamed(name, ...) \
|
2017-04-19 12:04:45 +00:00
|
|
|
do \
|
2013-01-25 23:34:20 +00:00
|
|
|
{ \
|
2017-05-22 20:12:57 +00:00
|
|
|
if (tr_logGetDeepEnabled()) \
|
2017-04-19 12:04:45 +00:00
|
|
|
{ \
|
2017-05-22 20:12:57 +00:00
|
|
|
tr_logAddDeep(__FILE__, __LINE__, name, __VA_ARGS__); \
|
2017-04-19 12:04:45 +00:00
|
|
|
} \
|
2013-01-25 23:34:20 +00:00
|
|
|
} \
|
2017-04-19 12:04:45 +00:00
|
|
|
while (0)
|
2013-01-25 23:34:20 +00:00
|
|
|
|
|
|
|
/** @brief set the buffer with the current time formatted for deep logging. */
|
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
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/** @} */
|