main: allow configuring log destination (stdout and/or syslog)

This commit is contained in:
Avi Kivity
2015-07-15 16:18:10 +03:00
parent 91d8d46709
commit f8a7c5bd2b
2 changed files with 8 additions and 2 deletions

View File

@@ -682,6 +682,8 @@ public:
val(logger_log_level, string_map, /* none */, Used,\
"map of logger name to log level. Valid values are trace, debug, info, warn, error. " \
"Use --help-loggers for a list of logger names") \
val(log_to_stdout, bool, true, Used, "Send log output to stdout") \
val(log_to_syslog, bool, false, Used, "Send log output to syslog") \
/* done! */
#define _make_value_member(name, type, deflt, status, desc, ...) \

View File

@@ -36,13 +36,16 @@ void do_help_loggers() {
}
}
void apply_logger_settings(sstring default_level, db::config::string_map levels) {
void apply_logger_settings(sstring default_level, db::config::string_map levels,
bool log_to_stdout, bool log_to_syslog) {
logging::logger_registry().set_all_loggers_level(boost::lexical_cast<logging::log_level>(std::string(default_level)));
for (auto&& kv: levels) {
auto&& k = kv.first;
auto&& v = kv.second;
logging::logger_registry().set_logger_level(k, boost::lexical_cast<logging::log_level>(std::string(v)));
}
logging::logger::set_stdout_enabled(log_to_stdout);
logging::logger::set_syslog_enabled(log_to_syslog);
}
int main(int ac, char** av) {
@@ -75,7 +78,8 @@ int main(int ac, char** av) {
auto&& opts = app.configuration();
return read_config(opts, *cfg).then([&cfg, &db, &qp, &proxy, &ctx, &opts]() {
apply_logger_settings(cfg->default_log_level(), cfg->logger_log_level());
apply_logger_settings(cfg->default_log_level(), cfg->logger_log_level(),
cfg->log_to_stdout(), cfg->log_to_syslog());
dht::set_global_partitioner(cfg->partitioner());
uint16_t thrift_port = cfg->rpc_port();
uint16_t cql_port = cfg->native_transport_port();