diff --git a/db/config.hh b/db/config.hh index f42adada16..865cb95539 100644 --- a/db/config.hh +++ b/db/config.hh @@ -677,6 +677,11 @@ public: val(ssl_storage_port, uint32_t, 7001, Unused, \ "The SSL port for encrypted communication. Unused unless enabled in encryption_options." \ ) \ + val(default_log_level, sstring, "warn", Used, \ + "Default log level for log messages. Valid values are trace, debug, info, warn, error.") \ + 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") \ /* done! */ #define _make_value_member(name, type, deflt, status, desc, ...) \ diff --git a/main.cc b/main.cc index 6c2c1ce850..da6662ae77 100644 --- a/main.cc +++ b/main.cc @@ -16,6 +16,7 @@ #include "streaming/stream_session.hh" #include "db/system_keyspace.hh" #include "dns.hh" +#include "log.hh" #include namespace bpo = boost::program_options; @@ -28,18 +29,36 @@ read_config(bpo::variables_map& opts, db::config& cfg) { return cfg.read_from_file(opts["options-file"].as()); } +void do_help_loggers() { + print("Available loggers:\n"); + for (auto&& name : logging::logger_registry().get_all_logger_names()) { + print(" %s\n", name); + } +} + +void apply_logger_settings(sstring default_level, db::config::string_map levels) { + logging::logger_registry().set_all_loggers_level(boost::lexical_cast(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(std::string(v))); + } +} + int main(int ac, char** av) { std::setvbuf(stdout, nullptr, _IOLBF, 1000); app_template app; auto opt_add = app.add_options(); auto cfg = make_lw_shared(); + bool help_loggers = false; cfg->add_options(opt_add) ("api-port", bpo::value()->default_value(10000), "Http Rest API port") ("api-dir", bpo::value()->default_value("swagger-ui/dist/"), "The directory location of the API GUI") // TODO : default, always read? ("options-file", bpo::value(), "cassandra.yaml file to read options from") + ("help-loggers", bpo::bool_switch(&help_loggers), "print a list of logger names and exit") ; distributed db; @@ -48,9 +67,15 @@ int main(int ac, char** av) { api::http_context ctx(db, proxy); return app.run(ac, av, [&] { + if (help_loggers) { + do_help_loggers(); + engine().exit(1); + return make_ready_future<>(); + } 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()); dht::set_global_partitioner(cfg->partitioner()); uint16_t thrift_port = cfg->rpc_port(); uint16_t cql_port = cfg->native_transport_port();