2019-06-14 14:00:37 +00:00
|
|
|
#include "OwnPatternFormatter.h"
|
2017-04-26 14:31:25 +00:00
|
|
|
|
2019-06-14 14:00:37 +00:00
|
|
|
#include <functional>
|
|
|
|
#include <optional>
|
2020-02-16 08:44:34 +00:00
|
|
|
#include <sys/time.h>
|
2017-04-26 14:31:25 +00:00
|
|
|
#include <IO/WriteBufferFromString.h>
|
|
|
|
#include <IO/WriteHelpers.h>
|
2020-02-03 02:33:31 +00:00
|
|
|
#include <Common/HashTable/Hash.h>
|
2018-06-15 17:32:35 +00:00
|
|
|
#include <Interpreters/InternalTextLogsQueue.h>
|
2019-06-14 14:00:37 +00:00
|
|
|
#include <Common/CurrentThread.h>
|
2021-10-02 07:13:14 +00:00
|
|
|
#include <base/getThreadId.h>
|
|
|
|
#include <base/terminalColors.h>
|
2019-06-14 14:00:37 +00:00
|
|
|
#include "Loggers.h"
|
2017-04-26 14:31:25 +00:00
|
|
|
|
|
|
|
|
2021-05-04 17:43:23 +00:00
|
|
|
OwnPatternFormatter::OwnPatternFormatter(bool color_)
|
|
|
|
: Poco::PatternFormatter(""), color(color_)
|
2019-06-14 14:00:37 +00:00
|
|
|
{
|
|
|
|
}
|
2018-06-15 17:32:35 +00:00
|
|
|
|
|
|
|
|
2021-05-05 10:36:54 +00:00
|
|
|
void OwnPatternFormatter::formatExtended(const DB::ExtendedLogMessage & msg_ext, std::string & text) const
|
2017-04-26 14:31:25 +00:00
|
|
|
{
|
|
|
|
DB::WriteBufferFromString wb(text);
|
|
|
|
|
2018-06-15 17:32:35 +00:00
|
|
|
const Poco::Message & msg = msg_ext.base;
|
|
|
|
|
2017-04-26 14:31:25 +00:00
|
|
|
/// Change delimiters in date for compatibility with old logs.
|
2018-06-15 17:32:35 +00:00
|
|
|
DB::writeDateTimeText<'.', ':'>(msg_ext.time_seconds, wb);
|
2017-04-26 14:31:25 +00:00
|
|
|
|
|
|
|
DB::writeChar('.', wb);
|
2018-06-15 17:32:35 +00:00
|
|
|
DB::writeChar('0' + ((msg_ext.time_microseconds / 100000) % 10), wb);
|
|
|
|
DB::writeChar('0' + ((msg_ext.time_microseconds / 10000) % 10), wb);
|
|
|
|
DB::writeChar('0' + ((msg_ext.time_microseconds / 1000) % 10), wb);
|
|
|
|
DB::writeChar('0' + ((msg_ext.time_microseconds / 100) % 10), wb);
|
|
|
|
DB::writeChar('0' + ((msg_ext.time_microseconds / 10) % 10), wb);
|
|
|
|
DB::writeChar('0' + ((msg_ext.time_microseconds / 1) % 10), wb);
|
|
|
|
|
2018-06-28 20:04:13 +00:00
|
|
|
writeCString(" [ ", wb);
|
2020-02-03 02:33:31 +00:00
|
|
|
if (color)
|
2020-02-16 08:44:34 +00:00
|
|
|
writeString(setColor(intHash64(msg_ext.thread_id)), wb);
|
2020-02-02 02:27:15 +00:00
|
|
|
DB::writeIntText(msg_ext.thread_id, wb);
|
2020-02-03 02:33:31 +00:00
|
|
|
if (color)
|
|
|
|
writeCString(resetColor(), wb);
|
2018-06-28 20:04:13 +00:00
|
|
|
writeCString(" ] ", wb);
|
|
|
|
|
2018-09-24 18:44:40 +00:00
|
|
|
/// We write query_id even in case when it is empty (no query context)
|
|
|
|
/// just to be convenient for various log parsers.
|
|
|
|
writeCString("{", wb);
|
2020-02-03 02:33:31 +00:00
|
|
|
if (color)
|
2020-02-16 08:44:34 +00:00
|
|
|
writeString(setColor(std::hash<std::string>()(msg_ext.query_id)), wb);
|
2018-09-24 18:44:40 +00:00
|
|
|
DB::writeString(msg_ext.query_id, wb);
|
2020-02-03 02:33:31 +00:00
|
|
|
if (color)
|
|
|
|
writeCString(resetColor(), wb);
|
2018-09-24 18:44:40 +00:00
|
|
|
writeCString("} ", wb);
|
2017-04-26 14:31:25 +00:00
|
|
|
|
2018-07-04 13:29:31 +00:00
|
|
|
writeCString("<", wb);
|
2020-02-03 02:48:10 +00:00
|
|
|
int priority = static_cast<int>(msg.getPriority());
|
2020-02-03 02:47:28 +00:00
|
|
|
if (color)
|
|
|
|
writeCString(setColorForLogPriority(priority), wb);
|
2020-02-03 02:48:10 +00:00
|
|
|
DB::writeString(getPriorityName(priority), wb);
|
2020-02-03 02:47:28 +00:00
|
|
|
if (color)
|
|
|
|
writeCString(resetColor(), wb);
|
2017-04-26 14:31:25 +00:00
|
|
|
writeCString("> ", wb);
|
2020-04-17 23:31:54 +00:00
|
|
|
if (color)
|
|
|
|
writeString(setColor(std::hash<std::string>()(msg.getSource())), wb);
|
2017-04-26 14:31:25 +00:00
|
|
|
DB::writeString(msg.getSource(), wb);
|
2020-04-17 23:31:54 +00:00
|
|
|
if (color)
|
|
|
|
writeCString(resetColor(), wb);
|
2017-04-26 14:31:25 +00:00
|
|
|
writeCString(": ", wb);
|
|
|
|
DB::writeString(msg.getText(), wb);
|
|
|
|
}
|
2018-06-15 17:32:35 +00:00
|
|
|
|
|
|
|
void OwnPatternFormatter::format(const Poco::Message & msg, std::string & text)
|
|
|
|
{
|
|
|
|
formatExtended(DB::ExtendedLogMessage::getFrom(msg), text);
|
|
|
|
}
|