2023-02-11 20:49:42 +00:00
|
|
|
// This file Copyright © 2010-2023 Mnemosyne LLC.
|
2022-08-08 18:05:39 +00:00
|
|
|
// It may be used under GPLv2 (SPDX: GPL-2.0-only), GPLv3 (SPDX: GPL-3.0-only),
|
2022-01-20 18:27:56 +00: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
|
|
|
|
2022-04-25 01:49:52 +00:00
|
|
|
#include <cstddef>
|
2022-03-17 22:39:06 +00:00
|
|
|
#include <ctime>
|
2022-03-18 19:15:43 +00:00
|
|
|
#include <optional>
|
2022-08-12 00:59:58 +00:00
|
|
|
#include <string>
|
2022-03-11 21:09:22 +00:00
|
|
|
#include <string_view>
|
2014-09-21 18:01:36 +00:00
|
|
|
|
2023-01-07 14:27:54 +00:00
|
|
|
// ---
|
2022-03-18 19:15:43 +00:00
|
|
|
|
2022-03-17 22:39:06 +00:00
|
|
|
enum tr_log_level
|
|
|
|
{
|
|
|
|
// No logging at all
|
|
|
|
TR_LOG_OFF,
|
2013-01-25 23:34:20 +00:00
|
|
|
|
2022-03-17 22:39:06 +00: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 22:39:06 +00: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 19:15:43 +00:00
|
|
|
std::optional<tr_log_level> tr_logGetLevelFromKey(std::string_view key);
|
|
|
|
|
2023-01-07 14:27:54 +00:00
|
|
|
// ---
|
2022-03-18 19:15:43 +00:00
|
|
|
|
2022-03-17 22:39:06 +00:00
|
|
|
struct tr_log_message
|
2013-01-25 23:34:20 +00:00
|
|
|
{
|
2022-03-17 22:39:06 +00:00
|
|
|
tr_log_level level;
|
2013-01-25 23:34:20 +00:00
|
|
|
|
2022-03-17 22:39:06 +00:00
|
|
|
// location in the source code
|
2022-08-12 00:59:58 +00:00
|
|
|
std::string_view file;
|
2022-12-18 16:23:44 +00:00
|
|
|
long line;
|
2022-03-14 04:43:35 +00:00
|
|
|
|
2022-03-17 22:39:06 +00:00
|
|
|
// when the message was generated
|
|
|
|
time_t when;
|
|
|
|
|
|
|
|
// torrent name or code module name associated with the message
|
2022-08-12 00:59:58 +00:00
|
|
|
std::string name;
|
2022-03-17 22:39:06 +00:00
|
|
|
|
|
|
|
// the message
|
2022-08-12 00:59:58 +00:00
|
|
|
std::string message;
|
2022-03-17 22:39:06 +00:00
|
|
|
|
|
|
|
// linked list of messages
|
|
|
|
struct tr_log_message* next;
|
|
|
|
};
|
|
|
|
|
2023-01-07 14:27:54 +00:00
|
|
|
// ---
|
2022-03-17 22:39:06 +00:00
|
|
|
|
|
|
|
#define TR_LOG_MAX_QUEUE_LENGTH 10000
|
2013-01-25 23:34:20 +00:00
|
|
|
|
2022-03-17 22:39:06 +00:00
|
|
|
[[nodiscard]] bool tr_logGetQueueEnabled();
|
|
|
|
|
2022-09-07 16:04:28 +00:00
|
|
|
void tr_logSetQueueEnabled(bool is_enabled);
|
2022-03-17 22:39:06 +00:00
|
|
|
|
|
|
|
[[nodiscard]] tr_log_message* tr_logGetQueue();
|
|
|
|
|
|
|
|
void tr_logFreeQueue(tr_log_message* freeme);
|
|
|
|
|
2023-01-07 14:27:54 +00:00
|
|
|
// ---
|
2022-03-17 22:39:06 +00:00
|
|
|
|
|
|
|
void tr_logSetLevel(tr_log_level);
|
|
|
|
|
|
|
|
[[nodiscard]] tr_log_level tr_logGetLevel();
|
|
|
|
|
|
|
|
[[nodiscard]] bool tr_logLevelIsActive(tr_log_level level);
|
|
|
|
|
2023-01-07 14:27:54 +00:00
|
|
|
// ---
|
2022-03-17 22:39:06 +00:00
|
|
|
|
|
|
|
void tr_logAddMessage(
|
|
|
|
char const* source_file,
|
2022-12-18 16:23:44 +00:00
|
|
|
long source_line,
|
2022-03-17 22:39:06 +00:00
|
|
|
tr_log_level level,
|
2022-08-03 06:15:37 +00:00
|
|
|
std::string_view msg,
|
2022-03-22 16:45:56 +00:00
|
|
|
std::string_view module_name = {});
|
2022-03-17 22:39:06 +00:00
|
|
|
|
|
|
|
#define tr_logAddLevel(level, ...) \
|
2017-04-19 12:04:45 +00:00
|
|
|
do \
|
2013-01-25 23:34:20 +00:00
|
|
|
{ \
|
2022-07-16 20:25:44 +00:00
|
|
|
if (tr_logLevelIsActive(level)) \
|
2017-04-19 12:04:45 +00:00
|
|
|
{ \
|
2022-03-17 22:39:06 +00:00
|
|
|
tr_logAddMessage(__FILE__, __LINE__, level, __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-17 22:39:06 +00: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 14:27:54 +00:00
|
|
|
// ---
|
2013-01-25 23:34:20 +00:00
|
|
|
|
2022-03-17 22:39:06 +00:00
|
|
|
char* tr_logGetTimeStr(char* buf, size_t buflen);
|