diff --git a/programs/client/Client.cpp b/programs/client/Client.cpp index 4951106f595..0c4141c74f2 100644 --- a/programs/client/Client.cpp +++ b/programs/client/Client.cpp @@ -1007,9 +1007,6 @@ void Client::addOptions(OptionsDescription & options_description) ("max_client_network_bandwidth", po::value(), "the maximum speed of data exchange over the network for the client in bytes per second.") ("compression", po::value(), "enable or disable compression") - ("log-level", po::value(), "client log level") - ("server_logs_file", po::value(), "put server logs into specified file") - ("query-fuzzer-runs", po::value()->default_value(0), "After executing every SELECT query, do random mutations in it and run again specified number of times. This is used for testing to discover unexpected corner cases.") ("interleave-queries-file", po::value>()->multitoken(), "file path with queries to execute before every file from 'queries-file'; multiple files can be specified (--queries-file file1 file2...); this is needed to enable more aggressive fuzzing of newly added tests (see 'query-fuzzer-runs' option)") @@ -1125,8 +1122,6 @@ void Client::processOptions(const OptionsDescription & options_description, max_client_network_bandwidth = options["max_client_network_bandwidth"].as(); if (options.count("compression")) config().setBool("compression", options["compression"].as()); - if (options.count("server_logs_file")) - server_logs_file = options["server_logs_file"].as(); if (options.count("no-warnings")) config().setBool("no-warnings", true); diff --git a/programs/local/LocalServer.cpp b/programs/local/LocalServer.cpp index 9753e7f7c5d..dc7daf2846a 100644 --- a/programs/local/LocalServer.cpp +++ b/programs/local/LocalServer.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -182,23 +183,6 @@ void LocalServer::initialize(Poco::Util::Application & self) auto loaded_config = config_processor.loadConfig(); config().add(loaded_config.configuration.duplicate(), PRIO_DEFAULT, false); } - - if (config().has("logger.console") || config().has("logger.level") || config().has("logger.log")) - { - // force enable logging - config().setString("logger", "logger"); - // sensitive data rules are not used here - buildLoggers(config(), logger(), "clickhouse-local"); - } - else - { - // Turn off server logging to stderr - if (!config().has("verbose")) - { - Poco::Logger::root().setLevel("none"); - Poco::Logger::root().setChannel(Poco::AutoPtr(new Poco::NullChannel())); - } - } } @@ -497,6 +481,35 @@ void LocalServer::processConfig() } print_stack_trace = config().getBool("stacktrace", false); + auto logging = (config().has("logger.console") + || config().has("logger.level") + || config().has("log-level") + || config().has("logger.log")); + + auto file_logging = config().has("server_logs_file"); + if (is_interactive && logging && !file_logging) + throw Exception("For interactive mode logging is allowed only with --server_logs_file option", + ErrorCodes::BAD_ARGUMENTS); + + if (file_logging) + { + auto level = Poco::Logger::parseLevel(config().getString("log-level", "trace")); + Poco::Logger::root().setLevel(level); + Poco::Logger::root().setChannel(Poco::AutoPtr(new Poco::SimpleFileChannel(server_logs_file))); + } + else if (logging) + { + // force enable logging + config().setString("logger", "logger"); + // sensitive data rules are not used here + buildLoggers(config(), logger(), "clickhouse-local"); + } + else + { + Poco::Logger::root().setLevel("none"); + Poco::Logger::root().setChannel(Poco::AutoPtr(new Poco::NullChannel())); + } + shared_context = Context::createShared(); global_context = Context::createGlobal(shared_context.get()); diff --git a/src/Client/ClientBase.cpp b/src/Client/ClientBase.cpp index 6f2b178067f..ebc6c7d3107 100644 --- a/src/Client/ClientBase.cpp +++ b/src/Client/ClientBase.cpp @@ -1612,9 +1612,13 @@ void ClientBase::init(int argc, char ** argv) ("disable_suggestion,A", "Disable loading suggestion data. Note that suggestion data is loaded asynchronously through a second connection to ClickHouse server. Also it is reasonable to disable suggestion if you want to paste a query with TAB characters. Shorthand option -A is for those who get used to mysql client.") ("time,t", "print query execution time to stderr in non-interactive mode (for benchmarks)") + ("echo", "in batch mode, print query before execution") ("verbose", "print query and other debugging info") + ("log-level", po::value(), "log level") + ("server_logs_file", po::value(), "put server logs into specified file") + ("multiline,m", "multiline") ("multiquery,n", "multiquery") @@ -1701,6 +1705,8 @@ void ClientBase::init(int argc, char ** argv) config().setBool("verbose", true); if (options.count("log-level")) Poco::Logger::root().setLevel(options["log-level"].as()); + if (options.count("server_logs_file")) + server_logs_file = options["server_logs_file"].as(); if (options.count("hardware-utilization")) progress_indication.print_hardware_utilization = true;