mirror of
https://github.com/EvernodeXRPL/hpcore.git
synced 2026-04-29 15:37:59 +00:00
Updated hpfs binary off_t return type fix. Introduced hpfs log level to hp config. (#300)
Updated hpfs binary off_t return type fix. Introduced hpfs log level to hp config
This commit is contained in:
28
src/conf.cpp
28
src/conf.cpp
@@ -177,9 +177,11 @@ namespace conf
|
||||
cfg.user.port = 8080;
|
||||
cfg.user.idle_timeout = 0;
|
||||
|
||||
cfg.hpfs.log.log_level = "err";
|
||||
|
||||
cfg.log.max_file_count = 50;
|
||||
cfg.log.max_mbytes_per_file = 10;
|
||||
cfg.log.loglevel = "inf";
|
||||
cfg.log.log_level = "inf";
|
||||
cfg.log.loggers.emplace("console");
|
||||
cfg.log.loggers.emplace("file");
|
||||
|
||||
@@ -475,6 +477,9 @@ namespace conf
|
||||
{
|
||||
const jsoncons::ojson &hpfs = d["hpfs"];
|
||||
cfg.hpfs.external = hpfs["external"].as<bool>();
|
||||
|
||||
const jsoncons::ojson &hpfs_log = hpfs["log"];
|
||||
cfg.hpfs.log.log_level = hpfs_log["log_level"].as<std::string>();
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
@@ -490,8 +495,9 @@ namespace conf
|
||||
try
|
||||
{
|
||||
const jsoncons::ojson &log = d["log"];
|
||||
cfg.log.loglevel = log["loglevel"].as<std::string>();
|
||||
cfg.log.loglevel_type = get_loglevel_type(cfg.log.loglevel);
|
||||
cfg.log.log_level = log["log_level"].as<std::string>();
|
||||
cfg.log.log_level_type = get_loglevel_type(cfg.log.log_level);
|
||||
|
||||
cfg.log.max_mbytes_per_file = log["max_mbytes_per_file"].as<size_t>();
|
||||
cfg.log.max_file_count = log["max_file_count"].as<size_t>();
|
||||
cfg.log.loggers.clear();
|
||||
@@ -593,13 +599,18 @@ namespace conf
|
||||
{
|
||||
jsoncons::ojson hpfs_config;
|
||||
hpfs_config.insert_or_assign("external", cfg.hpfs.external);
|
||||
|
||||
jsoncons::ojson hpfs_log_config;
|
||||
hpfs_log_config.insert_or_assign("log_level", cfg.hpfs.log.log_level);
|
||||
|
||||
hpfs_config.insert_or_assign("log", hpfs_log_config);
|
||||
d.insert_or_assign("hpfs", hpfs_config);
|
||||
}
|
||||
|
||||
// Log configs.
|
||||
{
|
||||
jsoncons::ojson log_config;
|
||||
log_config.insert_or_assign("loglevel", cfg.log.loglevel);
|
||||
log_config.insert_or_assign("log_level", cfg.log.log_level);
|
||||
log_config.insert_or_assign("max_mbytes_per_file", cfg.log.max_mbytes_per_file);
|
||||
log_config.insert_or_assign("max_file_count", cfg.log.max_file_count);
|
||||
|
||||
@@ -638,7 +649,7 @@ namespace conf
|
||||
fields_invalid |= cfg.contract.id.empty() && std::cerr << "Invalid value for contract id.\n";
|
||||
fields_invalid |= cfg.mesh.port == 0 && std::cerr << "Invalid value for mesh port\n";
|
||||
fields_invalid |= cfg.user.port == 0 && std::cerr << "Invalid value for user port\n";
|
||||
fields_invalid |= cfg.log.loglevel.empty() && std::cerr << "Invalid value for loglevel\n";
|
||||
fields_invalid |= cfg.log.log_level.empty() && std::cerr << "Invalid value for loglevel\n";
|
||||
fields_invalid |= cfg.log.loggers.empty() && std::cerr << "Invalid value for loggers\n";
|
||||
|
||||
if (fields_invalid)
|
||||
@@ -656,11 +667,16 @@ namespace conf
|
||||
|
||||
// Log settings
|
||||
const std::unordered_set<std::string> valid_loglevels({"dbg", "inf", "wrn", "err"});
|
||||
if (valid_loglevels.count(cfg.log.loglevel) != 1)
|
||||
if (valid_loglevels.count(cfg.log.log_level) != 1)
|
||||
{
|
||||
std::cerr << "Invalid loglevel configured. Valid values: dbg|inf|wrn|err\n";
|
||||
return -1;
|
||||
}
|
||||
else if (valid_loglevels.count(cfg.hpfs.log.log_level) != 1)
|
||||
{
|
||||
std::cerr << "Invalid hpfs loglevel configured. Valid values: dbg|inf|wrn|err\n";
|
||||
return -1;
|
||||
}
|
||||
|
||||
const std::unordered_set<std::string> valid_loggers({"console", "file"});
|
||||
for (const std::string &logger : cfg.log.loggers)
|
||||
|
||||
42
src/conf.hpp
42
src/conf.hpp
@@ -59,24 +59,6 @@ namespace conf
|
||||
uint64_t max_raw_shards = 0; // Maximum number of shards for raw data shards.
|
||||
};
|
||||
|
||||
// Log severity levels used in Hot Pocket.
|
||||
enum LOG_SEVERITY
|
||||
{
|
||||
DEBUG,
|
||||
INFO,
|
||||
WARN,
|
||||
ERROR
|
||||
};
|
||||
|
||||
struct log_config
|
||||
{
|
||||
std::string loglevel; // Log severity level (debug, info, warn, error)
|
||||
LOG_SEVERITY loglevel_type; // Log severity level enum (debug, info, warn, error)
|
||||
std::unordered_set<std::string> loggers; // List of enabled loggers (console, file)
|
||||
size_t max_mbytes_per_file = 0; // Max MB size of a single log file.
|
||||
size_t max_file_count = 0; // Max no. of log files to keep.
|
||||
};
|
||||
|
||||
struct node_config
|
||||
{
|
||||
// Config elements which are initialized in memory (these are not directly loaded from the config file)
|
||||
@@ -167,9 +149,15 @@ namespace conf
|
||||
peer_discovery_config peer_discovery; // Peer discovery configs.
|
||||
};
|
||||
|
||||
struct hpfs_log_config
|
||||
{
|
||||
std::string log_level; // Log severity level (dbg, inf, wrn, wrr)
|
||||
};
|
||||
|
||||
struct hpfs_config
|
||||
{
|
||||
bool external = false; // Whether to refrain from manageing built-in hpfs process or not.
|
||||
hpfs_log_config log;
|
||||
};
|
||||
|
||||
// Holds contextual information about the currently loaded contract.
|
||||
@@ -198,6 +186,24 @@ namespace conf
|
||||
struct flock config_lock; // Config file lock.
|
||||
};
|
||||
|
||||
// Log severity levels used in Hot Pocket.
|
||||
enum LOG_SEVERITY
|
||||
{
|
||||
DEBUG,
|
||||
INFO,
|
||||
WARN,
|
||||
ERROR
|
||||
};
|
||||
|
||||
struct log_config
|
||||
{
|
||||
std::string log_level; // Log severity level (dbg, inf, wrn, wrr)
|
||||
LOG_SEVERITY log_level_type; // Log severity level enum (debug, info, warn, error)
|
||||
std::unordered_set<std::string> loggers; // List of enabled loggers (console, file)
|
||||
size_t max_mbytes_per_file = 0; // Max MB size of a single log file.
|
||||
size_t max_file_count = 0; // Max no. of log files to keep.
|
||||
};
|
||||
|
||||
// Holds all the config values.
|
||||
struct hp_config
|
||||
{
|
||||
|
||||
@@ -9,9 +9,6 @@
|
||||
|
||||
namespace hpfs
|
||||
{
|
||||
constexpr const char *TRACE_ARG_ERROR = "trace=error";
|
||||
// Trace is set to error intentionally to prevent log pollution in debug mode. Change this in hpfs specific debugging.
|
||||
constexpr const char *TRACE_ARG_DEBUG = "trace=error";
|
||||
constexpr const char *RW_SESSION = "/::hpfs.rw.hmap";
|
||||
constexpr const char *RO_SESSION = "/::hpfs.ro.";
|
||||
constexpr const char *RO_SESSION_HMAP = "/::hpfs.ro.hmap.";
|
||||
@@ -134,7 +131,7 @@ namespace hpfs
|
||||
// hpfs process.
|
||||
util::fork_detach();
|
||||
|
||||
const char *active_hpfs_trace_arg = (conf::cfg.log.loglevel_type == conf::LOG_SEVERITY::DEBUG ? TRACE_ARG_DEBUG : TRACE_ARG_ERROR);
|
||||
const std::string trace_arg = "trace=" + conf::cfg.hpfs.log.log_level;
|
||||
|
||||
// Fill process args.
|
||||
char *execv_args[] = {
|
||||
@@ -144,7 +141,7 @@ namespace hpfs
|
||||
(char *)mount_dir.data(),
|
||||
// In full history mode, we disable log merge of hpfs.
|
||||
(char *)(is_full_history ? "merge=false" : "merge=true"),
|
||||
(char *)active_hpfs_trace_arg,
|
||||
(char *)trace_arg.data(),
|
||||
NULL};
|
||||
|
||||
const int ret = execv(execv_args[0], execv_args);
|
||||
|
||||
@@ -61,11 +61,11 @@ namespace hplog
|
||||
{
|
||||
plog::Severity level;
|
||||
|
||||
if (conf::cfg.log.loglevel_type == conf::LOG_SEVERITY::DEBUG)
|
||||
if (conf::cfg.log.log_level_type == conf::LOG_SEVERITY::DEBUG)
|
||||
level = plog::Severity::debug;
|
||||
else if (conf::cfg.log.loglevel_type == conf::LOG_SEVERITY::INFO)
|
||||
else if (conf::cfg.log.log_level_type == conf::LOG_SEVERITY::INFO)
|
||||
level = plog::Severity::info;
|
||||
else if (conf::cfg.log.loglevel_type == conf::LOG_SEVERITY::WARN)
|
||||
else if (conf::cfg.log.log_level_type == conf::LOG_SEVERITY::WARN)
|
||||
level = plog::Severity::warning;
|
||||
else
|
||||
level = plog::Severity::error;
|
||||
|
||||
BIN
test/bin/hpfs
BIN
test/bin/hpfs
Binary file not shown.
Reference in New Issue
Block a user