#include "OwnSplitChannel.h" #include #include #include #include #include #include #include #include #include namespace DB { void OwnSplitChannel::log(const Poco::Message & msg) { auto logs_queue = CurrentThread::getInternalTextLogsQueue(); if (channels.empty() && (logs_queue == nullptr || msg.getPriority() > logs_queue->max_priority)) return; ExtendedLogMessage msg_ext = ExtendedLogMessage::getFrom(msg); /// Log data to child channels for (auto & channel : channels) { if (channel.second) channel.second->logExtended(msg_ext); // extended child else channel.first->log(msg); // ordinary child } /// Log to "TCP queue" if message is not too noisy if (logs_queue && msg.getPriority() <= logs_queue->max_priority) { MutableColumns columns = InternalTextLogsQueue::getSampleColumns(); size_t i = 0; columns[i++]->insert(msg_ext.time_seconds); columns[i++]->insert(msg_ext.time_microseconds); columns[i++]->insert(DNSResolver::instance().getHostName()); columns[i++]->insert(msg_ext.query_id); columns[i++]->insert(msg_ext.thread_number); columns[i++]->insert(Int64(msg.getPriority())); columns[i++]->insert(msg.getSource()); columns[i++]->insert(msg.getText()); logs_queue->emplace(std::move(columns)); } /// Also log to system.text_log table TextLogElement elem; elem.event_time = msg_ext.time_seconds; elem.microseconds = msg_ext.time_microseconds; elem.thread_name = getThreadName(); elem.thread_number = msg_ext.thread_number; try { elem.os_thread_id = CurrentThread::get().os_thread_id; } catch (...) { elem.os_thread_id = 0; } elem.query_id = msg_ext.query_id; elem.message = msg.getText(); elem.logger_name = msg.getSource(); elem.level = msg.getPriority(); if (msg.getSourceFile() != nullptr) elem.source_file = msg.getSourceFile(); elem.source_line = msg.getSourceLine(); if (auto log = text_log.lock()) log->add(elem); } void OwnSplitChannel::addChannel(Poco::AutoPtr channel) { channels.emplace_back(std::move(channel), dynamic_cast(channel.get())); } void OwnSplitChannel::addTextLog(std::shared_ptr log) { text_log = log; } }