mirror of
https://github.com/transmission/transmission.git
synced 2026-05-02 06:33:04 +01:00
refactor: set logging levels (#2755)
This commit is contained in:
@@ -41,6 +41,7 @@
|
||||
|
||||
#include "error-types.h"
|
||||
#include "error.h"
|
||||
#include "file.h"
|
||||
#include "log.h"
|
||||
#include "mime-types.h"
|
||||
#include "net.h" // ntohl()
|
||||
@@ -51,8 +52,6 @@
|
||||
|
||||
using namespace std::literals;
|
||||
|
||||
#define logtrace(...) tr_logAddNamed(TR_LOG_TRACE, nullptr, __VA_ARGS__)
|
||||
|
||||
time_t __tr_current_time = 0;
|
||||
|
||||
/***
|
||||
@@ -227,21 +226,19 @@ void tr_timerAddMsec(struct event* timer, int msec)
|
||||
|
||||
uint8_t* tr_loadFile(char const* path, size_t* size, tr_error** error)
|
||||
{
|
||||
char const* const err_fmt = _("Couldn't read \"%1$s\": %2$s");
|
||||
|
||||
/* try to stat the file */
|
||||
auto info = tr_sys_path_info{};
|
||||
tr_error* my_error = nullptr;
|
||||
if (!tr_sys_path_get_info(path, 0, &info, &my_error))
|
||||
{
|
||||
tr_logAddDebug(err_fmt, path, my_error->message);
|
||||
tr_logAddError("Couldn't read \"%1$s\": %2$s", path, my_error->message);
|
||||
tr_error_propagate(error, &my_error);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (info.type != TR_SYS_PATH_IS_FILE)
|
||||
{
|
||||
tr_logAddError(err_fmt, path, _("Not a regular file"));
|
||||
tr_logAddError("Couldn't read \"%1$s\": Not a regular file", path);
|
||||
tr_error_set(error, TR_ERROR_EISDIR, "Not a regular file"sv);
|
||||
return nullptr;
|
||||
}
|
||||
@@ -256,7 +253,7 @@ uint8_t* tr_loadFile(char const* path, size_t* size, tr_error** error)
|
||||
auto const fd = tr_sys_file_open(path, TR_SYS_FILE_READ | TR_SYS_FILE_SEQUENTIAL, 0, &my_error);
|
||||
if (fd == TR_BAD_SYS_FILE)
|
||||
{
|
||||
tr_logAddError(err_fmt, path, my_error->message);
|
||||
tr_logAddError("Couldn't read \"%1$s\": %2$s", path, my_error->message);
|
||||
tr_error_propagate(error, &my_error);
|
||||
return nullptr;
|
||||
}
|
||||
@@ -264,7 +261,7 @@ uint8_t* tr_loadFile(char const* path, size_t* size, tr_error** error)
|
||||
auto* buf = static_cast<uint8_t*>(tr_malloc(info.size + 1));
|
||||
if (!tr_sys_file_read(fd, buf, info.size, nullptr, &my_error))
|
||||
{
|
||||
tr_logAddError(err_fmt, path, my_error->message);
|
||||
tr_logAddError("Couldn't read \"%1$s\": %2$s", path, my_error->message);
|
||||
tr_sys_file_close(fd, nullptr);
|
||||
tr_free(buf);
|
||||
tr_error_propagate(error, &my_error);
|
||||
@@ -279,7 +276,6 @@ uint8_t* tr_loadFile(char const* path, size_t* size, tr_error** error)
|
||||
|
||||
bool tr_loadFile(std::vector<char>& setme, std::string const& path, tr_error** error)
|
||||
{
|
||||
char const* const err_fmt = _("Couldn't read \"%1$s\": %2$s");
|
||||
auto const* const path_sz = path.c_str();
|
||||
|
||||
/* try to stat the file */
|
||||
@@ -287,14 +283,14 @@ bool tr_loadFile(std::vector<char>& setme, std::string const& path, tr_error** e
|
||||
tr_error* my_error = nullptr;
|
||||
if (!tr_sys_path_get_info(path_sz, 0, &info, &my_error))
|
||||
{
|
||||
tr_logAddDebug(err_fmt, path_sz, my_error->message);
|
||||
tr_logAddError(_("Couldn't read \"%1$s\": %2$s"), path_sz, my_error->message);
|
||||
tr_error_propagate(error, &my_error);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (info.type != TR_SYS_PATH_IS_FILE)
|
||||
{
|
||||
tr_logAddError(err_fmt, path_sz, _("Not a regular file"));
|
||||
tr_logAddError(_("Couldn't read \"%1$s\": Not a regular file"), path_sz);
|
||||
tr_error_set(error, TR_ERROR_EISDIR, "Not a regular file"sv);
|
||||
return false;
|
||||
}
|
||||
@@ -303,7 +299,7 @@ bool tr_loadFile(std::vector<char>& setme, std::string const& path, tr_error** e
|
||||
auto const fd = tr_sys_file_open(path_sz, TR_SYS_FILE_READ | TR_SYS_FILE_SEQUENTIAL, 0, &my_error);
|
||||
if (fd == TR_BAD_SYS_FILE)
|
||||
{
|
||||
tr_logAddError(err_fmt, path_sz, my_error->message);
|
||||
tr_logAddError(_("Couldn't read \"%1$s\": %2$s"), path_sz, my_error->message);
|
||||
tr_error_propagate(error, &my_error);
|
||||
return false;
|
||||
}
|
||||
@@ -311,7 +307,7 @@ bool tr_loadFile(std::vector<char>& setme, std::string const& path, tr_error** e
|
||||
setme.resize(info.size);
|
||||
if (!tr_sys_file_read(fd, std::data(setme), info.size, nullptr, &my_error))
|
||||
{
|
||||
tr_logAddError(err_fmt, path_sz, my_error->message);
|
||||
tr_logAddError(_("Couldn't read \"%1$s\": %2$s"), path_sz, my_error->message);
|
||||
tr_sys_file_close(fd, nullptr);
|
||||
tr_error_propagate(error, &my_error);
|
||||
return false;
|
||||
@@ -364,7 +360,7 @@ bool tr_saveFile(std::string const& filename, std::string_view contents, tr_erro
|
||||
return false;
|
||||
}
|
||||
|
||||
logtrace("Saved \"%s\"", filename.c_str());
|
||||
tr_logAddTrace("Saved \"%s\"", filename.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user