mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-24 10:40:49 +00:00
Merge pull request #6322 from yandex/text-log-simplification
Text log simplification
This commit is contained in:
commit
af949cce84
@ -273,17 +273,13 @@ int Server::main(const std::vector<std::string> & /*args*/)
|
|||||||
* table engines could use Context on destroy.
|
* table engines could use Context on destroy.
|
||||||
*/
|
*/
|
||||||
LOG_INFO(log, "Shutting down storages.");
|
LOG_INFO(log, "Shutting down storages.");
|
||||||
if (text_log)
|
|
||||||
text_log->shutdown();
|
|
||||||
global_context->shutdown();
|
global_context->shutdown();
|
||||||
LOG_DEBUG(log, "Shutted down storages.");
|
LOG_DEBUG(log, "Shutted down storages.");
|
||||||
|
|
||||||
/** Explicitly destroy Context. It is more convenient than in destructor of Server, because logger is still available.
|
/** Explicitly destroy Context. It is more convenient than in destructor of Server, because logger is still available.
|
||||||
* At this moment, no one could own shared part of Context.
|
* At this moment, no one could own shared part of Context.
|
||||||
*/
|
*/
|
||||||
text_log.reset();
|
|
||||||
global_context.reset();
|
global_context.reset();
|
||||||
|
|
||||||
LOG_DEBUG(log, "Destroyed global context.");
|
LOG_DEBUG(log, "Destroyed global context.");
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -413,7 +409,7 @@ int Server::main(const std::vector<std::string> & /*args*/)
|
|||||||
main_config_zk_changed_event,
|
main_config_zk_changed_event,
|
||||||
[&](ConfigurationPtr config)
|
[&](ConfigurationPtr config)
|
||||||
{
|
{
|
||||||
setTextLog(text_log);
|
setTextLog(global_context->getTextLog());
|
||||||
buildLoggers(*config, logger());
|
buildLoggers(*config, logger());
|
||||||
global_context->setClustersConfig(config);
|
global_context->setClustersConfig(config);
|
||||||
global_context->setMacros(std::make_unique<Macros>(*config, "macros"));
|
global_context->setMacros(std::make_unique<Macros>(*config, "macros"));
|
||||||
@ -500,14 +496,11 @@ int Server::main(const std::vector<std::string> & /*args*/)
|
|||||||
|
|
||||||
LOG_INFO(log, "Loading metadata from " + path);
|
LOG_INFO(log, "Loading metadata from " + path);
|
||||||
|
|
||||||
/// Create text_log instance
|
|
||||||
text_log = createSystemLog<TextLog>(*global_context, "system", "text_log", global_context->getConfigRef(), "text_log");
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
loadMetadataSystem(*global_context);
|
loadMetadataSystem(*global_context);
|
||||||
/// After attaching system databases we can initialize system log.
|
/// After attaching system databases we can initialize system log.
|
||||||
global_context->initializeSystemLogs(text_log);
|
global_context->initializeSystemLogs();
|
||||||
/// After the system database is created, attach virtual system tables (in addition to query_log and part_log)
|
/// After the system database is created, attach virtual system tables (in addition to query_log and part_log)
|
||||||
attachSystemTablesServer(*global_context->getDatabase("system"), has_zookeeper);
|
attachSystemTablesServer(*global_context->getDatabase("system"), has_zookeeper);
|
||||||
/// Then, load remaining databases
|
/// Then, load remaining databases
|
||||||
|
@ -57,7 +57,6 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<Context> global_context;
|
std::unique_ptr<Context> global_context;
|
||||||
std::shared_ptr<TextLog> text_log;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1645,11 +1645,10 @@ Compiler & Context::getCompiler()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Context::initializeSystemLogs(std::shared_ptr<TextLog> text_log)
|
void Context::initializeSystemLogs()
|
||||||
{
|
{
|
||||||
auto lock = getLock();
|
auto lock = getLock();
|
||||||
shared->system_logs.emplace(*global_context, getConfigRef());
|
shared->system_logs.emplace(*global_context, getConfigRef());
|
||||||
shared->system_logs->text_log = text_log;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Context::hasTraceCollector()
|
bool Context::hasTraceCollector()
|
||||||
@ -1716,11 +1715,10 @@ std::shared_ptr<TextLog> Context::getTextLog()
|
|||||||
{
|
{
|
||||||
auto lock = getLock();
|
auto lock = getLock();
|
||||||
|
|
||||||
if (!shared->system_logs)
|
if (!shared->system_logs || !shared->system_logs->text_log)
|
||||||
if (auto log = shared->system_logs->text_log.lock())
|
return {};
|
||||||
return log;
|
|
||||||
|
|
||||||
return {};
|
return shared->system_logs->text_log;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -424,7 +424,7 @@ public:
|
|||||||
Compiler & getCompiler();
|
Compiler & getCompiler();
|
||||||
|
|
||||||
/// Call after initialization before using system logs. Call for global context.
|
/// Call after initialization before using system logs. Call for global context.
|
||||||
void initializeSystemLogs(std::shared_ptr<TextLog> text_log);
|
void initializeSystemLogs();
|
||||||
|
|
||||||
void initializeTraceCollector();
|
void initializeTraceCollector();
|
||||||
bool hasTraceCollector();
|
bool hasTraceCollector();
|
||||||
|
@ -47,6 +47,7 @@ SystemLogs::SystemLogs(Context & global_context, const Poco::Util::AbstractConfi
|
|||||||
query_thread_log = createSystemLog<QueryThreadLog>(global_context, "system", "query_thread_log", config, "query_thread_log");
|
query_thread_log = createSystemLog<QueryThreadLog>(global_context, "system", "query_thread_log", config, "query_thread_log");
|
||||||
part_log = createSystemLog<PartLog>(global_context, "system", "part_log", config, "part_log");
|
part_log = createSystemLog<PartLog>(global_context, "system", "part_log", config, "part_log");
|
||||||
trace_log = createSystemLog<TraceLog>(global_context, "system", "trace_log", config, "trace_log");
|
trace_log = createSystemLog<TraceLog>(global_context, "system", "trace_log", config, "trace_log");
|
||||||
|
text_log = createSystemLog<TextLog>(global_context, "system", "text_log", config, "text_log");
|
||||||
|
|
||||||
part_log_database = config.getString("part_log.database", "system");
|
part_log_database = config.getString("part_log.database", "system");
|
||||||
}
|
}
|
||||||
@ -67,6 +68,8 @@ void SystemLogs::shutdown()
|
|||||||
part_log->shutdown();
|
part_log->shutdown();
|
||||||
if (trace_log)
|
if (trace_log)
|
||||||
trace_log->shutdown();
|
trace_log->shutdown();
|
||||||
|
if (text_log)
|
||||||
|
text_log->shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -75,8 +75,7 @@ struct SystemLogs
|
|||||||
std::shared_ptr<QueryThreadLog> query_thread_log; /// Used to log query threads.
|
std::shared_ptr<QueryThreadLog> query_thread_log; /// Used to log query threads.
|
||||||
std::shared_ptr<PartLog> part_log; /// Used to log operations with parts
|
std::shared_ptr<PartLog> part_log; /// Used to log operations with parts
|
||||||
std::shared_ptr<TraceLog> trace_log; /// Used to log traces from query profiler
|
std::shared_ptr<TraceLog> trace_log; /// Used to log traces from query profiler
|
||||||
std::weak_ptr<TextLog> text_log; /// Used to log all text. We use weak_ptr, because this log is
|
std::shared_ptr<TextLog> text_log; /// Used to log all text messages.
|
||||||
/// a server's field.
|
|
||||||
|
|
||||||
String part_log_database;
|
String part_log_database;
|
||||||
};
|
};
|
||||||
|
@ -20,23 +20,25 @@ using DB::CurrentThread;
|
|||||||
|
|
||||||
/// Logs a message to a specified logger with that level.
|
/// Logs a message to a specified logger with that level.
|
||||||
|
|
||||||
#define LOG_SIMPLE(logger, message, priority, PRIORITY) do \
|
#define LOG_SIMPLE(logger, message, priority, PRIORITY) do \
|
||||||
{ \
|
{ \
|
||||||
const bool is_clients_log = (CurrentThread::getGroup() != nullptr) && \
|
const bool is_clients_log = (CurrentThread::getGroup() != nullptr) && \
|
||||||
(CurrentThread::getGroup()->client_logs_level >= (priority)); \
|
(CurrentThread::getGroup()->client_logs_level >= (priority)); \
|
||||||
if ((logger)->is((PRIORITY)) || is_clients_log) { \
|
if ((logger)->is((PRIORITY)) || is_clients_log) \
|
||||||
std::stringstream oss_internal_rare; \
|
{ \
|
||||||
oss_internal_rare << message; \
|
std::stringstream oss_internal_rare; \
|
||||||
if (auto channel = (logger)->getChannel()) { \
|
oss_internal_rare << message; \
|
||||||
std::string file_function; \
|
if (auto channel = (logger)->getChannel()) \
|
||||||
file_function += __FILE__; \
|
{ \
|
||||||
file_function += ", "; \
|
std::string file_function; \
|
||||||
file_function += __PRETTY_FUNCTION__; \
|
file_function += __FILE__; \
|
||||||
Message poco_message((logger)->name(), oss_internal_rare.str(), \
|
file_function += "; "; \
|
||||||
(PRIORITY), file_function.c_str(), __LINE__); \
|
file_function += __PRETTY_FUNCTION__; \
|
||||||
channel->log(poco_message); \
|
Message poco_message((logger)->name(), oss_internal_rare.str(), \
|
||||||
} \
|
(PRIORITY), file_function.c_str(), __LINE__); \
|
||||||
} \
|
channel->log(poco_message); \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
} while (false)
|
} while (false)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user