diff --git a/base/loggers/Loggers.cpp b/base/loggers/Loggers.cpp index 7c627ad2272..512e44f79c7 100644 --- a/base/loggers/Loggers.cpp +++ b/base/loggers/Loggers.cpp @@ -197,7 +197,6 @@ void Loggers::buildLoggers(Poco::Util::AbstractConfiguration & config, Poco::Log Poco::AutoPtr pf = new OwnPatternFormatter(color_enabled); Poco::AutoPtr log = new DB::OwnFormattingChannel(pf, new Poco::ConsoleChannel); - logger.warning("Logging " + console_log_level_string + " to console"); log->setLevel(console_log_level); split->addChannel(log, "console"); } diff --git a/programs/local/LocalServer.cpp b/programs/local/LocalServer.cpp index 613c86002f3..1dfb5c1d636 100644 --- a/programs/local/LocalServer.cpp +++ b/programs/local/LocalServer.cpp @@ -434,6 +434,11 @@ catch (...) return getCurrentExceptionCode(); } +void LocalServer::setLogger(const String & logs_level) +{ + config().setString("logger.level", logs_level); + updateLevels(config(), logger()); +} void LocalServer::processConfig() { @@ -463,19 +468,19 @@ void LocalServer::processConfig() || config().has("send_logs_level") || config().has("logger.log")); - auto level = Poco::Logger::parseLevel(config().getString("log-level", config().getString("send_logs_level", "trace"))); + auto level = config().getString("log-level", "trace"); if (config().has("server_logs_file")) { - Poco::Logger::root().setLevel(level); + auto poco_logs_level = Poco::Logger::parseLevel(level); + Poco::Logger::root().setLevel(poco_logs_level); Poco::Logger::root().setChannel(Poco::AutoPtr(new Poco::SimpleFileChannel(server_logs_file))); } - else if (logging) + else if (logging || is_interactive) { - // force enable logging config().setString("logger", "logger"); - Poco::Logger::root().setLevel(level); - // sensitive data rules are not used here + auto log_level_default = is_interactive && !logging ? "none" : level; + config().setString("logger.level", config().getString("log-level", config().getString("send_logs_level", log_level_default))); buildLoggers(config(), logger(), "clickhouse-local"); } else diff --git a/programs/local/LocalServer.h b/programs/local/LocalServer.h index 969af7f1b77..3ee6d80136e 100644 --- a/programs/local/LocalServer.h +++ b/programs/local/LocalServer.h @@ -46,6 +46,8 @@ protected: void processConfig() override; + void setLogger(const String & logs_level) override; + private: /** Composes CREATE subquery based on passed arguments (--structure --file --table and --input-format) * This query will be executed first, before queries passed through --query argument diff --git a/src/Client/ClientBase.cpp b/src/Client/ClientBase.cpp index 115d047e6e8..7f5b5b82082 100644 --- a/src/Client/ClientBase.cpp +++ b/src/Client/ClientBase.cpp @@ -1298,6 +1298,13 @@ void ClientBase::processParsedSingleQuery(const String & full_query, const Strin } } + if (const auto * set_query = parsed_query->as()) + { + const auto * logs_level_field = set_query->changes.tryGet(std::string_view{"send_logs_level"}); + if (logs_level_field) + setLogger(logs_level_field->safeGet()); + } + processed_rows = 0; written_first_block = false; progress_indication.resetProgress(); diff --git a/src/Client/ClientBase.h b/src/Client/ClientBase.h index ae6d090eaee..1ce8be94d39 100644 --- a/src/Client/ClientBase.h +++ b/src/Client/ClientBase.h @@ -95,6 +95,7 @@ protected: std::optional hosts_and_ports_description; }; + virtual void setLogger(const String &) { throw Exception(ErrorCodes::NOT_IMPLEMENTED, "Method `initializeLogger()` is not implemented for `{}`", getName()); } virtual void printHelpMessage(const OptionsDescription & options_description) = 0; virtual void addOptions(OptionsDescription & options_description) = 0; virtual void processOptions(const OptionsDescription & options_description,