Skip to content

Commit

Permalink
adding syslog_ident option ...
Browse files Browse the repository at this point in the history
  • Loading branch information
scuzzilla committed Sep 28, 2022
1 parent fc160be commit 6e62340
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
25 changes: 25 additions & 0 deletions src/utils/cfg_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,31 @@ bool LogsCfgHandler::lookup_logs_parameters(const std::string &cfg_path,
}
}

if (syslog_s.compare("true") == 0) {
bool syslog_ident = logs_params.exists("syslog_ident");
if (syslog_ident == true) {
libconfig::Setting &syslog_ident =
logs_params.lookup("syslog_ident");
try {
std::string syslog_ident_s = syslog_ident;
if (syslog_ident_s.empty() == false) {
params.insert({"syslog_ident", syslog_ident_s});
} else {
spdlog::get("multi-logger-boot")->
error("[syslog_ident] configuration "
"issue: [ {} ] is invalid", syslog_ident_s);
return false;
}
} catch (const libconfig::SettingTypeException &ste) {
spdlog::get("multi-logger-boot")->
error("[syslog_ident] configuration issue: {}", ste.what());
return false;
}
} else {
params.insert({"syslog_ident", "mdt-dialout-collector"});
}
}

bool console_log = logs_params.exists("console_log");
if (console_log == true) {
libconfig::Setting &console_log =
Expand Down
5 changes: 4 additions & 1 deletion src/utils/logs_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ bool LogsHandler::set_spdlog_sinks()

// Syslog
if (logs_cfg_parameters.at("syslog").compare("true") == 0) {
const std::string ident = "mdt-dialout-collector";
const std::string ident = logs_cfg_parameters.at("syslog_ident");
try {
auto spdlog_syslog =
std::make_shared<spdlog::sinks::syslog_sink_mt>(
Expand Down Expand Up @@ -106,6 +106,9 @@ bool LogsHandler::set_spdlog_sinks()
this->multi_logger = std::make_shared<spdlog::logger>
("multi-logger", begin(spdlog_sinks), end(spdlog_sinks));
this->multi_logger->set_level(spdlog::level::from_str(spdlog_level));
this->multi_logger->set_pattern(
"[%d-%m-%Y %T.%e] [%n] [%l] ["
+ logs_cfg_parameters.at("syslog_ident") + "] %v");
spdlog::register_logger(this->multi_logger);

return true;
Expand Down

0 comments on commit 6e62340

Please sign in to comment.