Merge pull request #35716 from kssenii/fix-local-logs-level

Fix send_logs_level for clickhouse local
This commit is contained in:
Anton Popov 2022-04-06 18:52:47 +02:00 committed by GitHub
commit 13cb564d1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 34 additions and 11 deletions

View File

@ -197,7 +197,6 @@ void Loggers::buildLoggers(Poco::Util::AbstractConfiguration & config, Poco::Log
Poco::AutoPtr<OwnPatternFormatter> pf = new OwnPatternFormatter(color_enabled); Poco::AutoPtr<OwnPatternFormatter> pf = new OwnPatternFormatter(color_enabled);
Poco::AutoPtr<DB::OwnFormattingChannel> log = new DB::OwnFormattingChannel(pf, new Poco::ConsoleChannel); Poco::AutoPtr<DB::OwnFormattingChannel> log = new DB::OwnFormattingChannel(pf, new Poco::ConsoleChannel);
logger.warning("Logging " + console_log_level_string + " to console");
log->setLevel(console_log_level); log->setLevel(console_log_level);
split->addChannel(log, "console"); split->addChannel(log, "console");
} }

View File

@ -1019,6 +1019,7 @@ void Client::processConfig()
global_context->setCurrentQueryId(query_id); global_context->setCurrentQueryId(query_id);
} }
print_stack_trace = config().getBool("stacktrace", false); print_stack_trace = config().getBool("stacktrace", false);
logging_initialized = true;
if (config().has("multiquery")) if (config().has("multiquery"))
is_multiquery = true; is_multiquery = true;

View File

@ -434,6 +434,14 @@ catch (...)
return getCurrentExceptionCode(); return getCurrentExceptionCode();
} }
void LocalServer::updateLoggerLevel(const String & logs_level)
{
if (!logging_initialized)
return;
config().setString("logger.level", logs_level);
updateLevels(config(), logger());
}
void LocalServer::processConfig() void LocalServer::processConfig()
{ {
@ -460,30 +468,31 @@ void LocalServer::processConfig()
auto logging = (config().has("logger.console") auto logging = (config().has("logger.console")
|| config().has("logger.level") || config().has("logger.level")
|| config().has("log-level") || config().has("log-level")
|| config().has("send_logs_level")
|| config().has("logger.log")); || config().has("logger.log"));
auto file_logging = config().has("server_logs_file"); auto level = config().getString("log-level", "trace");
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) if (config().has("server_logs_file"))
{ {
auto level = Poco::Logger::parseLevel(config().getString("log-level", "trace")); auto poco_logs_level = Poco::Logger::parseLevel(level);
Poco::Logger::root().setLevel(level); Poco::Logger::root().setLevel(poco_logs_level);
Poco::Logger::root().setChannel(Poco::AutoPtr<Poco::SimpleFileChannel>(new Poco::SimpleFileChannel(server_logs_file))); Poco::Logger::root().setChannel(Poco::AutoPtr<Poco::SimpleFileChannel>(new Poco::SimpleFileChannel(server_logs_file)));
logging_initialized = true;
} }
else if (logging) else if (logging || is_interactive)
{ {
// force enable logging
config().setString("logger", "logger"); config().setString("logger", "logger");
// 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"); buildLoggers(config(), logger(), "clickhouse-local");
logging_initialized = true;
} }
else else
{ {
Poco::Logger::root().setLevel("none"); Poco::Logger::root().setLevel("none");
Poco::Logger::root().setChannel(Poco::AutoPtr<Poco::NullChannel>(new Poco::NullChannel())); Poco::Logger::root().setChannel(Poco::AutoPtr<Poco::NullChannel>(new Poco::NullChannel()));
logging_initialized = false;
} }
shared_context = Context::createShared(); shared_context = Context::createShared();
@ -713,6 +722,8 @@ void LocalServer::processOptions(const OptionsDescription &, const CommandLineOp
config().setString("logger.log", options["logger.log"].as<std::string>()); config().setString("logger.log", options["logger.log"].as<std::string>());
if (options.count("logger.level")) if (options.count("logger.level"))
config().setString("logger.level", options["logger.level"].as<std::string>()); config().setString("logger.level", options["logger.level"].as<std::string>());
if (options.count("send_logs_level"))
config().setString("send_logs_level", options["send_logs_level"].as<std::string>());
} }
} }

View File

@ -46,6 +46,8 @@ protected:
void processConfig() override; void processConfig() override;
void updateLoggerLevel(const String & logs_level) override;
private: private:
/** Composes CREATE subquery based on passed arguments (--structure --file --table and --input-format) /** 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 * This query will be executed first, before queries passed through --query argument

View File

@ -1298,6 +1298,13 @@ void ClientBase::processParsedSingleQuery(const String & full_query, const Strin
} }
} }
if (const auto * set_query = parsed_query->as<ASTSetQuery>())
{
const auto * logs_level_field = set_query->changes.tryGet(std::string_view{"send_logs_level"});
if (logs_level_field)
updateLoggerLevel(logs_level_field->safeGet<String>());
}
processed_rows = 0; processed_rows = 0;
written_first_block = false; written_first_block = false;
progress_indication.resetProgress(); progress_indication.resetProgress();

View File

@ -95,6 +95,7 @@ protected:
std::optional<ProgramOptionsDescription> hosts_and_ports_description; std::optional<ProgramOptionsDescription> hosts_and_ports_description;
}; };
virtual void updateLoggerLevel(const String &) {}
virtual void printHelpMessage(const OptionsDescription & options_description) = 0; virtual void printHelpMessage(const OptionsDescription & options_description) = 0;
virtual void addOptions(OptionsDescription & options_description) = 0; virtual void addOptions(OptionsDescription & options_description) = 0;
virtual void processOptions(const OptionsDescription & options_description, virtual void processOptions(const OptionsDescription & options_description,
@ -265,6 +266,8 @@ protected:
bool allow_repeated_settings = false; bool allow_repeated_settings = false;
bool cancelled = false; bool cancelled = false;
bool logging_initialized = false;
}; };
} }