mirror of
https://github.com/XRPLF/clio.git
synced 2026-04-29 15:37:53 +00:00
perf: Add benchmark for Logger (#2407)
This commit is contained in:
@@ -168,21 +168,18 @@ initConsoleLogging(bool logToConsole, std::string const& format)
|
||||
* @param format The log format string.
|
||||
* @param dirPath The directory path where log files will be stored.
|
||||
*/
|
||||
static void
|
||||
initFileLogging(
|
||||
config::ClioConfigDefinition const& config,
|
||||
std::string const& format,
|
||||
std::filesystem::path const& dirPath
|
||||
)
|
||||
void
|
||||
LogService::initFileLogging(FileLoggingParams const& params, std::string const& format)
|
||||
{
|
||||
namespace keywords = boost::log::keywords;
|
||||
namespace sinks = boost::log::sinks;
|
||||
|
||||
auto const rotationPeriod = config.get<uint32_t>("log_rotation_hour_interval");
|
||||
|
||||
// the below are taken from user in MB, but boost::log::add_file_log needs it to be in bytes
|
||||
auto const rotationSize = mbToBytes(config.get<uint32_t>("log_rotation_size"));
|
||||
auto const dirSize = mbToBytes(config.get<uint32_t>("log_directory_max_size"));
|
||||
auto const rotationSize = mbToBytes(params.rotationSizeMB);
|
||||
auto const dirSize = mbToBytes(params.dirMaxSizeMB);
|
||||
|
||||
auto const dirPath = std::filesystem::path{params.logDir};
|
||||
|
||||
auto fileSink = boost::log::add_file_log(
|
||||
keywords::file_name = dirPath / "clio.log",
|
||||
keywords::target_file_name = dirPath / "clio_%Y-%m-%d_%H-%M-%S.log",
|
||||
@@ -190,7 +187,8 @@ initFileLogging(
|
||||
keywords::format = format,
|
||||
keywords::open_mode = std::ios_base::app,
|
||||
keywords::rotation_size = rotationSize,
|
||||
keywords::time_based_rotation = sinks::file::rotation_at_time_interval(boost::posix_time::hours(rotationPeriod))
|
||||
keywords::time_based_rotation =
|
||||
sinks::file::rotation_at_time_interval(boost::posix_time::hours(params.rotationHours))
|
||||
);
|
||||
fileSink->locked_backend()->set_file_collector(
|
||||
sinks::file::make_collector(keywords::target = dirPath, keywords::max_size = dirSize)
|
||||
@@ -274,7 +272,13 @@ LogService::init(config::ClioConfigDefinition const& config)
|
||||
};
|
||||
}
|
||||
}
|
||||
initFileLogging(config, format, dirPath);
|
||||
FileLoggingParams params{
|
||||
.logDir = logDir.value(),
|
||||
.rotationSizeMB = config.get<uint32_t>("log_rotation_size"),
|
||||
.dirMaxSizeMB = config.get<uint32_t>("log_directory_max_size"),
|
||||
.rotationHours = config.get<uint32_t>("log_rotation_hour_interval")
|
||||
};
|
||||
initFileLogging(params, format);
|
||||
}
|
||||
|
||||
// get default severity, can be overridden per channel using the `log_channels` array
|
||||
|
||||
@@ -51,6 +51,8 @@
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
|
||||
struct BenchmarkLoggingInitializer;
|
||||
|
||||
namespace util {
|
||||
|
||||
namespace config {
|
||||
@@ -362,6 +364,20 @@ public:
|
||||
*/
|
||||
[[nodiscard]] static bool
|
||||
enabled();
|
||||
|
||||
private:
|
||||
struct FileLoggingParams {
|
||||
std::string logDir;
|
||||
|
||||
uint32_t rotationSizeMB;
|
||||
uint32_t dirMaxSizeMB;
|
||||
uint32_t rotationHours;
|
||||
};
|
||||
|
||||
friend struct ::BenchmarkLoggingInitializer;
|
||||
|
||||
static void
|
||||
initFileLogging(FileLoggingParams const& params, std::string const& format);
|
||||
};
|
||||
|
||||
}; // namespace util
|
||||
|
||||
Reference in New Issue
Block a user