2023-11-01 22:11:11 +01:00
|
|
|
// This file Copyright © Mnemosyne LLC.
|
2022-08-08 13:05:39 -05:00
|
|
|
// It may be used under GPLv2 (SPDX: GPL-2.0-only), GPLv3 (SPDX: GPL-3.0-only),
|
2022-01-20 12:27:56 -06:00
|
|
|
// 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
|
|
|
|
2023-06-29 23:51:55 -05:00
|
|
|
#include <cstddef> // size_t
|
2022-03-17 17:39:06 -05:00
|
|
|
#include <ctime>
|
2022-03-18 14:15:43 -05:00
|
|
|
#include <optional>
|
2022-08-11 19:59:58 -05:00
|
|
|
#include <string>
|
2022-03-11 15:09:22 -06:00
|
|
|
#include <string_view>
|
2014-09-21 18:01:36 +00:00
|
|
|
|
2023-01-07 08:27:54 -06:00
|
|
|
// ---
|
2022-03-18 14:15:43 -05:00
|
|
|
|
2022-03-17 17:39:06 -05:00
|
|
|
enum tr_log_level
|
|
|
|
{
|
|
|
|
// No logging at all
|
|
|
|
TR_LOG_OFF,
|
2013-01-25 23:34:20 +00:00
|
|
|
|
2022-03-17 17:39:06 -05:00
|
|
|
// Errors that prevent Transmission from running
|
|
|
|
TR_LOG_CRITICAL,
|
|
|
|
|
|
|
|
// Errors that could prevent a single torrent from running, e.g. missing
|
|
|
|
// files or a private torrent's tracker responding "unregistered torrent"
|
|
|
|
TR_LOG_ERROR,
|
|
|
|
|
|
|
|
// Smaller errors that don't stop the overall system,
|
|
|
|
// e.g. unable to preallocate a file, or unable to connect to a tracker
|
|
|
|
// when other trackers are available
|
|
|
|
TR_LOG_WARN,
|
|
|
|
|
|
|
|
// User-visible info, e.g. "torrent completed" or "running script"
|
|
|
|
TR_LOG_INFO,
|
|
|
|
|
|
|
|
// Debug messages
|
|
|
|
TR_LOG_DEBUG,
|
2013-01-25 23:34:20 +00:00
|
|
|
|
2022-03-17 17:39:06 -05:00
|
|
|
// High-volume debug messages, e.g. tracing peer protocol messages
|
|
|
|
TR_LOG_TRACE
|
|
|
|
};
|
2013-01-25 23:34:20 +00:00
|
|
|
|
2022-03-18 14:15:43 -05:00
|
|
|
std::optional<tr_log_level> tr_logGetLevelFromKey(std::string_view key);
|
|
|
|
|
2023-01-07 08:27:54 -06:00
|
|
|
// ---
|
2022-03-18 14:15:43 -05:00
|
|
|
|
2022-03-17 17:39:06 -05:00
|
|
|
struct tr_log_message
|
2013-01-25 23:34:20 +00:00
|
|
|
{
|
2022-03-17 17:39:06 -05:00
|
|
|
tr_log_level level;
|
2013-01-25 23:34:20 +00:00
|
|
|
|
2022-03-17 17:39:06 -05:00
|
|
|
// location in the source code
|
2022-08-11 19:59:58 -05:00
|
|
|
std::string_view file;
|
2022-12-19 00:23:44 +08:00
|
|
|
long line;
|
2022-03-13 23:43:35 -05:00
|
|
|
|
2022-03-17 17:39:06 -05:00
|
|
|
// when the message was generated
|
|
|
|
time_t when;
|
|
|
|
|
|
|
|
// torrent name or code module name associated with the message
|
2022-08-11 19:59:58 -05:00
|
|
|
std::string name;
|
2022-03-17 17:39:06 -05:00
|
|
|
|
|
|
|
// the message
|
2022-08-11 19:59:58 -05:00
|
|
|
std::string message;
|
2022-03-17 17:39:06 -05:00
|
|
|
|
|
|
|
// linked list of messages
|
|
|
|
struct tr_log_message* next;
|
|
|
|
};
|
|
|
|
|
2023-01-07 08:27:54 -06:00
|
|
|
// ---
|
2022-03-17 17:39:06 -05:00
|
|
|
|
|
|
|
#define TR_LOG_MAX_QUEUE_LENGTH 10000
|
2013-01-25 23:34:20 +00:00
|
|
|
|
2022-09-07 11:04:28 -05:00
|
|
|
void tr_logSetQueueEnabled(bool is_enabled);
|
2022-03-17 17:39:06 -05:00
|
|
|
|
|
|
|
[[nodiscard]] tr_log_message* tr_logGetQueue();
|
|
|
|
|
|
|
|
void tr_logFreeQueue(tr_log_message* freeme);
|
|
|
|
|
2023-01-07 08:27:54 -06:00
|
|
|
// ---
|
2022-03-17 17:39:06 -05:00
|
|
|
|
|
|
|
void tr_logSetLevel(tr_log_level);
|
|
|
|
|
|
|
|
[[nodiscard]] tr_log_level tr_logGetLevel();
|
|
|
|
|
|
|
|
[[nodiscard]] bool tr_logLevelIsActive(tr_log_level level);
|
|
|
|
|
2023-01-07 08:27:54 -06:00
|
|
|
// ---
|
2022-03-17 17:39:06 -05:00
|
|
|
|
|
|
|
void tr_logAddMessage(
|
|
|
|
char const* source_file,
|
2022-12-19 00:23:44 +08:00
|
|
|
long source_line,
|
2022-03-17 17:39:06 -05:00
|
|
|
tr_log_level level,
|
2023-07-04 14:03:45 -05:00
|
|
|
std::string&& msg,
|
2022-03-22 11:45:56 -05:00
|
|
|
std::string_view module_name = {});
|
2022-03-17 17:39:06 -05:00
|
|
|
|
|
|
|
#define tr_logAddLevel(level, ...) \
|
2017-04-19 15:04:45 +03:00
|
|
|
do \
|
2013-01-25 23:34:20 +00:00
|
|
|
{ \
|
2022-07-16 15:25:44 -05:00
|
|
|
if (tr_logLevelIsActive(level)) \
|
2017-04-19 15:04:45 +03:00
|
|
|
{ \
|
2022-03-17 17:39:06 -05:00
|
|
|
tr_logAddMessage(__FILE__, __LINE__, level, __VA_ARGS__); \
|
2017-04-19 15:04:45 +03:00
|
|
|
} \
|
2021-08-15 12:41:48 +03:00
|
|
|
} while (0)
|
2013-01-25 23:34:20 +00:00
|
|
|
|
2022-03-17 17:39:06 -05:00
|
|
|
#define tr_logAddCritical(...) tr_logAddLevel(TR_LOG_CRITICAL, __VA_ARGS__)
|
|
|
|
#define tr_logAddError(...) tr_logAddLevel(TR_LOG_ERROR, __VA_ARGS__)
|
|
|
|
#define tr_logAddWarn(...) tr_logAddLevel(TR_LOG_WARN, __VA_ARGS__)
|
|
|
|
#define tr_logAddInfo(...) tr_logAddLevel(TR_LOG_INFO, __VA_ARGS__)
|
|
|
|
#define tr_logAddDebug(...) tr_logAddLevel(TR_LOG_DEBUG, __VA_ARGS__)
|
|
|
|
#define tr_logAddTrace(...) tr_logAddLevel(TR_LOG_TRACE, __VA_ARGS__)
|
2013-01-25 23:34:20 +00:00
|
|
|
|
2023-01-07 08:27:54 -06:00
|
|
|
// ---
|
2013-01-25 23:34:20 +00:00
|
|
|
|
2022-03-17 17:39:06 -05:00
|
|
|
char* tr_logGetTimeStr(char* buf, size_t buflen);
|