ClickHouse/src/Interpreters/TextLog.cpp

91 lines
3.3 KiB
C++
Raw Normal View History

2019-07-22 13:54:08 +00:00
#include <Interpreters/TextLog.h>
#include <Common/ClickHouseRevision.h>
#include <DataTypes/DataTypeDate.h>
2019-07-22 13:54:08 +00:00
#include <DataTypes/DataTypeDateTime.h>
#include <DataTypes/DataTypeDateTime64.h>
#include <DataTypes/DataTypeEnum.h>
#include <DataTypes/DataTypeLowCardinality.h>
2019-07-22 13:54:08 +00:00
#include <DataTypes/DataTypeString.h>
#include <DataTypes/DataTypesNumber.h>
2022-04-27 15:05:45 +00:00
#include <Common/logger_useful.h>
2019-07-22 13:54:08 +00:00
#include <array>
2019-07-22 15:09:33 +00:00
namespace DB
{
NamesAndTypesList TextLogElement::getNamesAndTypes()
2019-07-22 15:09:33 +00:00
{
auto priority_datatype = std::make_shared<DataTypeEnum8>(
DataTypeEnum8::Values
{
{"Fatal", static_cast<Int8>(Message::PRIO_FATAL)},
{"Critical", static_cast<Int8>(Message::PRIO_CRITICAL)},
{"Error", static_cast<Int8>(Message::PRIO_ERROR)},
{"Warning", static_cast<Int8>(Message::PRIO_WARNING)},
{"Notice", static_cast<Int8>(Message::PRIO_NOTICE)},
{"Information", static_cast<Int8>(Message::PRIO_INFORMATION)},
{"Debug", static_cast<Int8>(Message::PRIO_DEBUG)},
2021-09-06 10:11:19 +00:00
{"Trace", static_cast<Int8>(Message::PRIO_TRACE)},
{"Test", static_cast<Int8>(Message::PRIO_TEST)},
2019-07-22 15:09:33 +00:00
});
2019-07-22 13:54:08 +00:00
return
{
{"event_date", std::make_shared<DataTypeDate>()},
{"event_time", std::make_shared<DataTypeDateTime>()},
{"event_time_microseconds", std::make_shared<DataTypeDateTime64>(6)},
{"microseconds", std::make_shared<DataTypeUInt32>()},
2019-07-22 13:54:08 +00:00
{"thread_name", std::make_shared<DataTypeLowCardinality>(std::make_shared<DataTypeString>())},
{"thread_id", std::make_shared<DataTypeUInt64>()},
2019-07-22 13:54:08 +00:00
{"level", std::move(priority_datatype)},
{"query_id", std::make_shared<DataTypeString>()},
{"logger_name", std::make_shared<DataTypeLowCardinality>(std::make_shared<DataTypeString>())},
{"message", std::make_shared<DataTypeString>()},
2019-07-22 13:54:08 +00:00
{"revision", std::make_shared<DataTypeUInt32>()},
2019-07-22 15:09:33 +00:00
{"source_file", std::make_shared<DataTypeLowCardinality>(std::make_shared<DataTypeString>())},
{"source_line", std::make_shared<DataTypeUInt64>()}
2019-07-22 13:54:08 +00:00
};
}
void TextLogElement::appendToBlock(MutableColumns & columns) const
2019-07-22 13:54:08 +00:00
{
size_t i = 0;
Extended range of DateTime64 to years 1925 - 2238 The Year 1925 is a starting point because most of the timezones switched to saner (mostly 15-minutes based) offsets somewhere during 1924 or before. And that significantly simplifies implementation. 2238 is to simplify arithmetics for sanitizing LUT index access; there are less than 0x1ffff days from 1925. * Extended DateLUTImpl internal LUT to 0x1ffff items, some of which represent negative (pre-1970) time values. As a collateral benefit, Date now correctly supports dates up to 2149 (instead of 2106). * Added a new strong typedef ExtendedDayNum, which represents dates pre-1970 and post 2149. * Functions that used to return DayNum now return ExtendedDayNum. * Refactored DateLUTImpl to untie DayNum from the dual role of being a value and an index (due to negative time). Index is now a different type LUTIndex with explicit conversion functions from DatNum, time_t, and ExtendedDayNum. * Updated DateLUTImpl to properly support values close to epoch start (1970-01-01 00:00), including negative ones. * Reduced resolution of DateLUTImpl::Values::time_at_offset_change to multiple of 15-minutes to allow storing 64-bits of time_t in DateLUTImpl::Value while keeping same size. * Minor performance updates to DateLUTImpl when building month LUT by skipping non-start-of-month days. * Fixed extractTimeZoneFromFunctionArguments to work correctly with DateTime64. * New unit-tests and stateless integration tests for both DateTime and DateTime64.
2020-04-17 13:26:44 +00:00
columns[i++]->insert(DateLUT::instance().toDayNum(event_time).toUnderType());
2019-07-22 13:54:08 +00:00
columns[i++]->insert(event_time);
columns[i++]->insert(event_time_microseconds);
2019-07-22 13:54:08 +00:00
columns[i++]->insert(microseconds);
columns[i++]->insertData(thread_name.data(), thread_name.size());
2020-02-02 02:27:15 +00:00
columns[i++]->insert(thread_id);
2019-07-22 13:54:08 +00:00
2019-07-22 15:09:33 +00:00
columns[i++]->insert(level);
2019-07-22 13:54:08 +00:00
columns[i++]->insert(query_id);
columns[i++]->insert(logger_name);
columns[i++]->insert(message);
2020-09-17 12:15:05 +00:00
columns[i++]->insert(ClickHouseRevision::getVersionRevision());
2019-07-22 15:09:33 +00:00
2019-07-22 13:54:08 +00:00
columns[i++]->insert(source_file);
columns[i++]->insert(source_line);
}
TextLog::TextLog(ContextPtr context_, const String & database_name_,
const String & table_name_, const String & storage_def_,
size_t flush_interval_milliseconds_)
: SystemLog<TextLogElement>(context_, database_name_, table_name_,
storage_def_, flush_interval_milliseconds_)
{
// SystemLog methods may write text logs, so we disable logging for the text
// log table to avoid recursion.
log->setLevel(0);
}
2019-07-22 13:54:08 +00:00
}