1#include <Interpreters/TextLog.h>
2#include <DataTypes/DataTypeEnum.h>
3#include <DataTypes/DataTypesNumber.h>
4#include <DataTypes/DataTypeDateTime.h>
5#include <DataTypes/DataTypeDate.h>
6#include <DataTypes/DataTypeString.h>
7#include <Common/ClickHouseRevision.h>
8#include <array>
9
10namespace DB
11{
12
13Block TextLogElement::createBlock()
14{
15 auto priority_datatype = std::make_shared<DataTypeEnum8>(
16 DataTypeEnum8::Values
17 {
18 {"Fatal", static_cast<Int8>(Message::PRIO_FATAL)},
19 {"Critical", static_cast<Int8>(Message::PRIO_CRITICAL)},
20 {"Error", static_cast<Int8>(Message::PRIO_ERROR)},
21 {"Warning", static_cast<Int8>(Message::PRIO_WARNING)},
22 {"Notice", static_cast<Int8>(Message::PRIO_NOTICE)},
23 {"Information", static_cast<Int8>(Message::PRIO_INFORMATION)},
24 {"Debug", static_cast<Int8>(Message::PRIO_DEBUG)},
25 {"Trace", static_cast<Int8>(Message::PRIO_TRACE)}
26 });
27
28 return
29 {
30 {std::make_shared<DataTypeDate>(), "event_date"},
31 {std::make_shared<DataTypeDateTime>(), "event_time"},
32 {std::make_shared<DataTypeUInt32>(), "microseconds"},
33
34 {std::make_shared<DataTypeLowCardinality>(std::make_shared<DataTypeString>()), "thread_name"},
35 {std::make_shared<DataTypeUInt32>(), "thread_number"},
36 {std::make_shared<DataTypeUInt32>(), "os_thread_id"},
37
38 {std::move(priority_datatype), "level"},
39 {std::make_shared<DataTypeString>(), "query_id"},
40 {std::make_shared<DataTypeLowCardinality>(std::make_shared<DataTypeString>()), "logger_name"},
41 {std::make_shared<DataTypeString>(), "message"},
42
43 {std::make_shared<DataTypeUInt32>(), "revision"},
44
45 {std::make_shared<DataTypeLowCardinality>(std::make_shared<DataTypeString>()), "source_file"},
46 {std::make_shared<DataTypeUInt64>(), "source_line"}
47 };
48}
49
50void TextLogElement::appendToBlock(Block & block) const
51{
52 MutableColumns columns = block.mutateColumns();
53
54 size_t i = 0;
55
56 columns[i++]->insert(DateLUT::instance().toDayNum(event_time));
57 columns[i++]->insert(event_time);
58 columns[i++]->insert(microseconds);
59
60 columns[i++]->insertData(thread_name.data(), thread_name.size());
61 columns[i++]->insert(thread_number);
62 columns[i++]->insert(os_thread_id);
63
64 columns[i++]->insert(level);
65 columns[i++]->insert(query_id);
66 columns[i++]->insert(logger_name);
67 columns[i++]->insert(message);
68
69 columns[i++]->insert(ClickHouseRevision::get());
70
71 columns[i++]->insert(source_file);
72 columns[i++]->insert(source_line);
73}
74
75}
76