2019-06-14 14:00:37 +00:00
|
|
|
#include "OwnSplitChannel.h"
|
2018-06-15 17:32:35 +00:00
|
|
|
|
2019-06-14 14:00:37 +00:00
|
|
|
#include <iostream>
|
2018-06-15 17:32:35 +00:00
|
|
|
#include <Core/Block.h>
|
2019-06-14 14:00:37 +00:00
|
|
|
#include <Interpreters/InternalTextLogsQueue.h>
|
2019-07-22 13:54:08 +00:00
|
|
|
#include <Interpreters/TextLog.h>
|
2019-06-14 14:00:37 +00:00
|
|
|
#include <sys/time.h>
|
2018-06-15 17:32:35 +00:00
|
|
|
#include <Poco/Message.h>
|
2019-06-14 14:00:37 +00:00
|
|
|
#include <Common/CurrentThread.h>
|
|
|
|
#include <Common/DNSResolver.h>
|
2019-04-17 14:53:54 +00:00
|
|
|
#include <common/getThreadNumber.h>
|
2018-06-15 17:32:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2019-07-19 07:44:18 +00:00
|
|
|
if (auto masker = sensitive_data_masker.load())
|
2019-06-20 07:17:21 +00:00
|
|
|
{
|
|
|
|
auto message_text = msg.getText();
|
2019-07-19 07:44:18 +00:00
|
|
|
auto matches = masker->wipeSensitiveData(message_text);
|
2019-06-20 07:17:21 +00:00
|
|
|
if (matches > 0)
|
|
|
|
{
|
|
|
|
logSplit({msg, message_text}); // we will continue with the copy of original message with text modified
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
logSplit(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void OwnSplitChannel::logSplit(const Poco::Message & msg)
|
|
|
|
{
|
2018-06-15 17:32:35 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2019-06-20 07:17:21 +00:00
|
|
|
auto logs_queue = CurrentThread::getInternalTextLogsQueue();
|
|
|
|
|
2018-06-15 17:32:35 +00:00
|
|
|
/// 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;
|
2018-10-22 08:54:54 +00:00
|
|
|
columns[i++]->insert(msg_ext.time_seconds);
|
|
|
|
columns[i++]->insert(msg_ext.time_microseconds);
|
2018-06-15 17:32:35 +00:00
|
|
|
columns[i++]->insert(DNSResolver::instance().getHostName());
|
|
|
|
columns[i++]->insert(msg_ext.query_id);
|
2018-10-22 08:54:54 +00:00
|
|
|
columns[i++]->insert(msg_ext.thread_number);
|
|
|
|
columns[i++]->insert(Int64(msg.getPriority()));
|
2018-06-15 17:32:35 +00:00
|
|
|
columns[i++]->insert(msg.getSource());
|
|
|
|
columns[i++]->insert(msg.getText());
|
|
|
|
|
|
|
|
logs_queue->emplace(std::move(columns));
|
|
|
|
}
|
2018-06-20 15:21:42 +00:00
|
|
|
|
2019-07-22 13:54:08 +00:00
|
|
|
|
2019-07-30 14:04:18 +00:00
|
|
|
/// Also log to system.text_log table
|
|
|
|
TextLogElement elem;
|
2019-07-22 13:54:08 +00:00
|
|
|
|
2019-07-30 14:04:18 +00:00
|
|
|
elem.event_time = msg_ext.time_seconds;
|
|
|
|
elem.microseconds = msg_ext.time_microseconds;
|
2019-07-22 13:54:08 +00:00
|
|
|
|
2019-07-30 14:04:18 +00:00
|
|
|
elem.thread_name = getThreadName();
|
|
|
|
elem.thread_number = msg_ext.thread_number;
|
2019-08-12 15:28:28 +00:00
|
|
|
|
|
|
|
if (CurrentThread::isInitialized())
|
|
|
|
elem.os_thread_id = CurrentThread::get().os_thread_id;
|
|
|
|
else
|
2019-07-30 14:04:18 +00:00
|
|
|
elem.os_thread_id = 0;
|
2019-07-22 13:54:08 +00:00
|
|
|
|
2019-07-30 14:04:18 +00:00
|
|
|
elem.query_id = msg_ext.query_id;
|
2019-07-22 15:09:33 +00:00
|
|
|
|
2019-07-30 14:04:18 +00:00
|
|
|
elem.message = msg.getText();
|
|
|
|
elem.logger_name = msg.getSource();
|
|
|
|
elem.level = msg.getPriority();
|
2019-07-22 13:54:08 +00:00
|
|
|
|
2019-07-30 14:04:18 +00:00
|
|
|
if (msg.getSourceFile() != nullptr)
|
|
|
|
elem.source_file = msg.getSourceFile();
|
|
|
|
|
|
|
|
elem.source_line = msg.getSourceLine();
|
|
|
|
|
2019-07-31 14:42:23 +00:00
|
|
|
std::lock_guard<std::mutex> lock(text_log_mutex);
|
2019-07-30 14:04:18 +00:00
|
|
|
if (auto log = text_log.lock())
|
|
|
|
log->add(elem);
|
2018-06-15 17:32:35 +00:00
|
|
|
}
|
|
|
|
|
2019-06-20 07:17:21 +00:00
|
|
|
|
|
|
|
void OwnSplitChannel::setMasker(DB::SensitiveDataMasker * _sensitive_data_masker)
|
|
|
|
{
|
2019-07-19 07:44:18 +00:00
|
|
|
sensitive_data_masker.store(_sensitive_data_masker);
|
2019-06-20 07:17:21 +00:00
|
|
|
}
|
|
|
|
|
2018-06-15 17:32:35 +00:00
|
|
|
void OwnSplitChannel::addChannel(Poco::AutoPtr<Poco::Channel> channel)
|
|
|
|
{
|
|
|
|
channels.emplace_back(std::move(channel), dynamic_cast<ExtendedLogChannel *>(channel.get()));
|
|
|
|
}
|
|
|
|
|
2019-07-31 14:03:23 +00:00
|
|
|
void OwnSplitChannel::addTextLog(std::shared_ptr<DB::TextLog> log)
|
2019-07-30 14:04:18 +00:00
|
|
|
{
|
2019-07-31 14:42:23 +00:00
|
|
|
std::lock_guard<std::mutex> lock(text_log_mutex);
|
2019-07-30 14:04:18 +00:00
|
|
|
text_log = log;
|
|
|
|
}
|
2018-06-15 17:32:35 +00:00
|
|
|
|
|
|
|
}
|