mirror of
https://github.com/KingDuckZ/kamokan.git
synced 2024-11-27 00:43:47 +00:00
Setup the logger based on the log_file setting in tawashi.ini.
With this change I had to swap the order in which what settings file as being loaded and the initialization of the logger itself. This is because the logger now depends on the settings file, so it can't be used before the setting file got parsed.
This commit is contained in:
parent
10da16051c
commit
ed4a02f4bb
2 changed files with 16 additions and 9 deletions
|
@ -5,3 +5,4 @@ redis_mode = inet
|
||||||
base_uri = http://127.0.0.1:8080
|
base_uri = http://127.0.0.1:8080
|
||||||
website_root = @CMAKE_CURRENT_BINARY_DIR@/html
|
website_root = @CMAKE_CURRENT_BINARY_DIR@/html
|
||||||
logging_level = debug
|
logging_level = debug
|
||||||
|
log_file = @CMAKE_CURRENT_BINARY_DIR@/tawashi.log
|
||||||
|
|
|
@ -78,6 +78,7 @@ namespace {
|
||||||
parSettings.add_default("truncate_long_pasties", "false");
|
parSettings.add_default("truncate_long_pasties", "false");
|
||||||
parSettings.add_default("logging_level", "err");
|
parSettings.add_default("logging_level", "err");
|
||||||
parSettings.add_default("resubmit_wait", "10");
|
parSettings.add_default("resubmit_wait", "10");
|
||||||
|
parSettings.add_default("log_file", "-");
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_buildtime_info() {
|
void print_buildtime_info() {
|
||||||
|
@ -107,9 +108,20 @@ namespace {
|
||||||
return SafeStackObject<IniFile>(istream_iterator<char>(conf), istream_iterator<char>());
|
return SafeStackObject<IniFile>(istream_iterator<char>(conf), istream_iterator<char>());
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_logging_level (const tawashi::SettingsBag& parSettings) {
|
std::shared_ptr<spdlog::logger> setup_logging (const tawashi::SettingsBag& parSettings) {
|
||||||
|
//Prepare the logger
|
||||||
|
spdlog::set_pattern("[%Y-%m-%d %T %z] - %v");
|
||||||
|
spdlog::set_level(spdlog::level::trace); //set to maximum possible here
|
||||||
|
boost::string_ref log_path = parSettings["log_file"];
|
||||||
|
const bool log_to_stderr = (log_path == boost::string_ref("-"));
|
||||||
|
auto statuslog = (log_to_stderr ?
|
||||||
|
spdlog::stderr_logger_st("statuslog") :
|
||||||
|
spdlog::basic_logger_st("statuslog", std::string(log_path.begin(), log_path.end()), false)
|
||||||
|
);
|
||||||
|
|
||||||
auto logging_level = tawashi::LoggingLevels::_from_string_nocase(parSettings.as<std::string>("logging_level").c_str());
|
auto logging_level = tawashi::LoggingLevels::_from_string_nocase(parSettings.as<std::string>("logging_level").c_str());
|
||||||
spdlog::set_level(static_cast<decltype(spdlog::level::trace)>(logging_level._to_integral()));
|
spdlog::set_level(static_cast<decltype(spdlog::level::trace)>(logging_level._to_integral()));
|
||||||
|
return statuslog;
|
||||||
}
|
}
|
||||||
} //unnamed namespace
|
} //unnamed namespace
|
||||||
|
|
||||||
|
@ -126,18 +138,12 @@ int main (int parArgc, char* parArgv[], char* parEnvp[]) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Prepare the logger
|
|
||||||
spdlog::set_pattern("[%Y-%m-%d %T %z] - %v");
|
|
||||||
spdlog::set_level(spdlog::level::trace); //set to maximum possible here
|
|
||||||
auto statuslog = spdlog::stderr_logger_st("statuslog");
|
|
||||||
|
|
||||||
statuslog->info("Loading config: \"{}\"", config_file_path());
|
|
||||||
|
|
||||||
SafeStackObject<tawashi::IniFile> ini = load_ini();
|
SafeStackObject<tawashi::IniFile> ini = load_ini();
|
||||||
auto settings = SafeStackObject<tawashi::SettingsBag>(ini);
|
auto settings = SafeStackObject<tawashi::SettingsBag>(ini);
|
||||||
fill_defaults(*settings);
|
fill_defaults(*settings);
|
||||||
|
|
||||||
set_logging_level(*settings);
|
auto statuslog = setup_logging(*settings);
|
||||||
|
statuslog->info("Loaded config: \"{}\"", config_file_path());
|
||||||
|
|
||||||
auto cgi_env = SafeStackObject<tawashi::cgi::Env>(parEnvp);
|
auto cgi_env = SafeStackObject<tawashi::cgi::Env>(parEnvp);
|
||||||
tawashi::ResponseFactory resp_factory(settings, cgi_env);
|
tawashi::ResponseFactory resp_factory(settings, cgi_env);
|
||||||
|
|
Loading…
Reference in a new issue