mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 07:31:57 +00:00
reflected change requests asked on July 27
This commit is contained in:
parent
6406bd998a
commit
bec7408a0c
@ -68,7 +68,7 @@
|
|||||||
To enable JSON logging support, just uncomment <json> tag.
|
To enable JSON logging support, just uncomment <json> tag.
|
||||||
Having the <json> tag will make it work. For better understanding/visibility, you can add "true" or "1".
|
Having the <json> tag will make it work. For better understanding/visibility, you can add "true" or "1".
|
||||||
-->
|
-->
|
||||||
<!-- <json>true</json> -->
|
<!-- <formatting>json</formatting> -->
|
||||||
</logger>
|
</logger>
|
||||||
|
|
||||||
<!-- Add headers to response in options request. OPTIONS method is used in CORS preflight requests. -->
|
<!-- Add headers to response in options request. OPTIONS method is used in CORS preflight requests. -->
|
||||||
|
@ -1014,7 +1014,7 @@ void BaseDaemon::setupWatchdog()
|
|||||||
if (config().getRawString("logger.stream_compress", "false") == "true")
|
if (config().getRawString("logger.stream_compress", "false") == "true")
|
||||||
{
|
{
|
||||||
Poco::AutoPtr<OwnPatternFormatter> pf;
|
Poco::AutoPtr<OwnPatternFormatter> pf;
|
||||||
if (config().has("logger.json"))
|
if (config().getString("logger.formatting", "") == "json")
|
||||||
pf = new OwnJSONPatternFormatter;
|
pf = new OwnJSONPatternFormatter;
|
||||||
else
|
else
|
||||||
pf = new OwnPatternFormatter(true);
|
pf = new OwnPatternFormatter(true);
|
||||||
|
@ -99,7 +99,7 @@ void Loggers::buildLoggers(Poco::Util::AbstractConfiguration & config, Poco::Log
|
|||||||
|
|
||||||
Poco::AutoPtr<OwnPatternFormatter> pf;
|
Poco::AutoPtr<OwnPatternFormatter> pf;
|
||||||
|
|
||||||
if (config.has("logger.json"))
|
if (config.getString("logger.formatting", "") == "json")
|
||||||
pf = new OwnJSONPatternFormatter;
|
pf = new OwnJSONPatternFormatter;
|
||||||
else
|
else
|
||||||
pf = new OwnPatternFormatter(true);
|
pf = new OwnPatternFormatter(true);
|
||||||
@ -140,7 +140,7 @@ void Loggers::buildLoggers(Poco::Util::AbstractConfiguration & config, Poco::Log
|
|||||||
|
|
||||||
Poco::AutoPtr<OwnPatternFormatter> pf;
|
Poco::AutoPtr<OwnPatternFormatter> pf;
|
||||||
|
|
||||||
if (config.has("logger.json"))
|
if (config.getString("logger.formatting", "") == "json")
|
||||||
pf = new OwnJSONPatternFormatter;
|
pf = new OwnJSONPatternFormatter;
|
||||||
else
|
else
|
||||||
pf = new OwnPatternFormatter(true);
|
pf = new OwnPatternFormatter(true);
|
||||||
@ -184,7 +184,7 @@ void Loggers::buildLoggers(Poco::Util::AbstractConfiguration & config, Poco::Log
|
|||||||
|
|
||||||
Poco::AutoPtr<OwnPatternFormatter> pf;
|
Poco::AutoPtr<OwnPatternFormatter> pf;
|
||||||
|
|
||||||
if (config.has("logger.json"))
|
if (config.getString("logger.formatting", "") == "json")
|
||||||
pf = new OwnJSONPatternFormatter;
|
pf = new OwnJSONPatternFormatter;
|
||||||
else
|
else
|
||||||
pf = new OwnPatternFormatter(true);
|
pf = new OwnPatternFormatter(true);
|
||||||
@ -211,7 +211,7 @@ void Loggers::buildLoggers(Poco::Util::AbstractConfiguration & config, Poco::Log
|
|||||||
}
|
}
|
||||||
|
|
||||||
Poco::AutoPtr<OwnPatternFormatter> pf;
|
Poco::AutoPtr<OwnPatternFormatter> pf;
|
||||||
if (config.has("logger.json"))
|
if (config.getString("logger.formatting", "") == "json")
|
||||||
pf = new OwnJSONPatternFormatter;
|
pf = new OwnJSONPatternFormatter;
|
||||||
else
|
else
|
||||||
pf = new OwnPatternFormatter(color_enabled);
|
pf = new OwnPatternFormatter(color_enabled);
|
||||||
|
@ -1,20 +1,17 @@
|
|||||||
#include "OwnFormattingChannel.h"
|
#include "OwnFormattingChannel.h"
|
||||||
#include "OwnJSONPatternFormatter.h"
|
|
||||||
#include "OwnPatternFormatter.h"
|
#include "OwnPatternFormatter.h"
|
||||||
|
|
||||||
|
|
||||||
namespace DB
|
namespace DB
|
||||||
{
|
{
|
||||||
|
|
||||||
void OwnFormattingChannel::logExtended(const ExtendedLogMessage & msg)
|
void OwnFormattingChannel::logExtended(const ExtendedLogMessage & msg)
|
||||||
{
|
{
|
||||||
if (pChannel && priority >= msg.base.getPriority())
|
if (pChannel && priority >= msg.base.getPriority())
|
||||||
|
{
|
||||||
|
if (pFormatter)
|
||||||
{
|
{
|
||||||
std::string text;
|
std::string text;
|
||||||
if (auto * formatter = dynamic_cast<OwnJSONPatternFormatter *>(pFormatter.get()))
|
|
||||||
{
|
|
||||||
formatter->formatExtended(msg, text);
|
|
||||||
pChannel->log(Poco::Message(msg.base, text));
|
|
||||||
}
|
|
||||||
else if (pFormatter)
|
|
||||||
{
|
|
||||||
pFormatter->formatExtended(msg, text);
|
pFormatter->formatExtended(msg, text);
|
||||||
pChannel->log(Poco::Message(msg.base, text));
|
pChannel->log(Poco::Message(msg.base, text));
|
||||||
}
|
}
|
||||||
|
@ -13,19 +13,16 @@ OwnJSONPatternFormatter::OwnJSONPatternFormatter() : OwnPatternFormatter("")
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void OwnJSONPatternFormatter::formatExtended(const DB::ExtendedLogMessage & msg_ext, std::string & text)
|
void OwnJSONPatternFormatter::formatExtended(const DB::ExtendedLogMessage & msg_ext, std::string & text) const
|
||||||
{
|
{
|
||||||
DB::WriteBufferFromString wb(text);
|
DB::WriteBufferFromString wb(text);
|
||||||
|
|
||||||
DB::FormatSettings settings;
|
DB::FormatSettings settings;
|
||||||
char key_name[] = "a placeholder for key names in structured logging";
|
|
||||||
char empty_string[] = "";
|
|
||||||
|
|
||||||
const Poco::Message & msg = msg_ext.base;
|
const Poco::Message & msg = msg_ext.base;
|
||||||
DB::writeChar('{', wb);
|
DB::writeChar('{', wb);
|
||||||
|
|
||||||
strcpy(key_name, "date_time");
|
writeJSONString("date_time", wb, settings);
|
||||||
writeJSONString(key_name, key_name + strlen(key_name), wb, settings);
|
|
||||||
DB::writeChar(':', wb);
|
DB::writeChar(':', wb);
|
||||||
|
|
||||||
DB::writeChar('\"', wb);
|
DB::writeChar('\"', wb);
|
||||||
@ -42,20 +39,14 @@ void OwnJSONPatternFormatter::formatExtended(const DB::ExtendedLogMessage & msg_
|
|||||||
|
|
||||||
DB::writeChar(',', wb);
|
DB::writeChar(',', wb);
|
||||||
|
|
||||||
strcpy(key_name, "thread_name");
|
writeJSONString("thread_name", wb, settings);
|
||||||
writeJSONString(key_name, key_name + strlen(key_name), wb, settings);
|
|
||||||
DB::writeChar(':', wb);
|
DB::writeChar(':', wb);
|
||||||
|
|
||||||
const char * thread_name = msg.getThread().c_str();
|
writeJSONString(msg.getThread(), wb, settings);
|
||||||
if (thread_name != nullptr)
|
|
||||||
writeJSONString(thread_name, thread_name + strlen(thread_name), wb, settings);
|
|
||||||
else
|
|
||||||
writeJSONString(empty_string, empty_string + strlen(empty_string), wb, settings);
|
|
||||||
|
|
||||||
DB::writeChar(',', wb);
|
DB::writeChar(',', wb);
|
||||||
|
|
||||||
strcpy(key_name, "thread_id");
|
writeJSONString("thread_id", wb, settings);
|
||||||
writeJSONString(key_name, key_name + strlen(key_name), wb, settings);
|
|
||||||
DB::writeChar(':', wb);
|
DB::writeChar(':', wb);
|
||||||
DB::writeChar('\"', wb);
|
DB::writeChar('\"', wb);
|
||||||
DB::writeIntText(msg_ext.thread_id, wb);
|
DB::writeIntText(msg_ext.thread_id, wb);
|
||||||
@ -63,65 +54,38 @@ void OwnJSONPatternFormatter::formatExtended(const DB::ExtendedLogMessage & msg_
|
|||||||
|
|
||||||
DB::writeChar(',', wb);
|
DB::writeChar(',', wb);
|
||||||
|
|
||||||
strcpy(key_name, "level");
|
writeJSONString("level", wb, settings);
|
||||||
writeJSONString(key_name, key_name + strlen(key_name), wb, settings);
|
|
||||||
DB::writeChar(':', wb);
|
DB::writeChar(':', wb);
|
||||||
int priority_int = static_cast<int>(msg.getPriority());
|
int priority = static_cast<int>(msg.getPriority());
|
||||||
String priority_str = std::to_string(priority_int);
|
writeJSONString(std::to_string(priority), wb, settings);
|
||||||
const char * priority = priority_str.c_str();
|
|
||||||
if (priority != nullptr)
|
|
||||||
writeJSONString(priority, priority + strlen(priority), wb, settings);
|
|
||||||
else
|
|
||||||
writeJSONString(empty_string, empty_string + strlen(empty_string), wb, settings);
|
|
||||||
|
|
||||||
DB::writeChar(',', wb);
|
DB::writeChar(',', wb);
|
||||||
|
|
||||||
/// We write query_id even in case when it is empty (no query context)
|
/// We write query_id even in case when it is empty (no query context)
|
||||||
/// just to be convenient for various log parsers.
|
/// just to be convenient for various log parsers.
|
||||||
|
|
||||||
strcpy(key_name, "query_id");
|
writeJSONString("query_id", wb, settings);
|
||||||
writeJSONString(key_name, key_name + strlen(key_name), wb, settings);
|
|
||||||
DB::writeChar(':', wb);
|
DB::writeChar(':', wb);
|
||||||
writeJSONString(msg_ext.query_id, wb, settings);
|
writeJSONString(msg_ext.query_id, wb, settings);
|
||||||
|
|
||||||
DB::writeChar(',', wb);
|
DB::writeChar(',', wb);
|
||||||
|
|
||||||
strcpy(key_name, "logger_name");
|
writeJSONString("logger_name", wb, settings);
|
||||||
writeJSONString(key_name, key_name + strlen(key_name), wb, settings);
|
|
||||||
DB::writeChar(':', wb);
|
DB::writeChar(':', wb);
|
||||||
|
|
||||||
const char * logger_name = msg.getSource().c_str();
|
writeJSONString(msg.getSource(), wb, settings);
|
||||||
if (logger_name != nullptr)
|
|
||||||
writeJSONString(logger_name, logger_name + strlen(logger_name), wb, settings);
|
|
||||||
else
|
|
||||||
writeJSONString(empty_string, empty_string + strlen(empty_string), wb, settings);
|
|
||||||
|
|
||||||
DB::writeChar(',', wb);
|
DB::writeChar(',', wb);
|
||||||
|
|
||||||
strcpy(key_name, "message");
|
writeJSONString("message", wb, settings);
|
||||||
writeJSONString(key_name, key_name + strlen(key_name), wb, settings);
|
|
||||||
DB::writeChar(':', wb);
|
DB::writeChar(':', wb);
|
||||||
const char * msg_text = msg.getText().c_str();
|
writeJSONString(msg.getText(), wb, settings);
|
||||||
if (msg_text != nullptr)
|
|
||||||
writeJSONString(msg_text, msg_text + strlen(msg_text), wb, settings);
|
|
||||||
else
|
|
||||||
writeJSONString(empty_string, empty_string + strlen(empty_string), wb, settings);
|
|
||||||
|
|
||||||
DB::writeChar(',', wb);
|
DB::writeChar(',', wb);
|
||||||
|
|
||||||
strcpy(key_name, "source_file");
|
writeJSONString("source_file", wb, settings);
|
||||||
writeJSONString(key_name, key_name + strlen(key_name), wb, settings);
|
|
||||||
DB::writeChar(':', wb);
|
DB::writeChar(':', wb);
|
||||||
const char * source_file = msg.getSourceFile();
|
writeJSONString(msg.getSourceFile(), wb, settings);
|
||||||
if (source_file != nullptr)
|
|
||||||
writeJSONString(source_file, source_file + strlen(source_file), wb, settings);
|
|
||||||
else
|
|
||||||
writeJSONString(empty_string, empty_string + strlen(empty_string), wb, settings);
|
|
||||||
|
|
||||||
DB::writeChar(',', wb);
|
DB::writeChar(',', wb);
|
||||||
|
|
||||||
strcpy(key_name, "source_line");
|
writeJSONString("source_line", wb, settings);
|
||||||
writeJSONString(key_name, key_name + strlen(key_name), wb, settings);
|
|
||||||
DB::writeChar(':', wb);
|
DB::writeChar(':', wb);
|
||||||
DB::writeChar('\"', wb);
|
DB::writeChar('\"', wb);
|
||||||
DB::writeIntText(msg.getSourceLine(), wb);
|
DB::writeIntText(msg.getSourceLine(), wb);
|
||||||
|
@ -28,5 +28,5 @@ public:
|
|||||||
OwnJSONPatternFormatter();
|
OwnJSONPatternFormatter();
|
||||||
|
|
||||||
void format(const Poco::Message & msg, std::string & text) override;
|
void format(const Poco::Message & msg, std::string & text) override;
|
||||||
static void formatExtended(const DB::ExtendedLogMessage & msg_ext, std::string & text);
|
void formatExtended(const DB::ExtendedLogMessage & msg_ext, std::string & text) const override;
|
||||||
};
|
};
|
||||||
|
@ -13,10 +13,6 @@ OwnPatternFormatter::OwnPatternFormatter(bool color_) : Poco::PatternFormatter("
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
OwnPatternFormatter::OwnPatternFormatter() : Poco::PatternFormatter("")
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void OwnPatternFormatter::formatExtended(const DB::ExtendedLogMessage & msg_ext, std::string & text) const
|
void OwnPatternFormatter::formatExtended(const DB::ExtendedLogMessage & msg_ext, std::string & text) const
|
||||||
{
|
{
|
||||||
DB::WriteBufferFromString wb(text);
|
DB::WriteBufferFromString wb(text);
|
||||||
|
@ -25,10 +25,9 @@ class OwnPatternFormatter : public Poco::PatternFormatter
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
OwnPatternFormatter(bool color_ = false);
|
OwnPatternFormatter(bool color_ = false);
|
||||||
OwnPatternFormatter();
|
|
||||||
|
|
||||||
void format(const Poco::Message & msg, std::string & text) override;
|
void format(const Poco::Message & msg, std::string & text) override;
|
||||||
void formatExtended(const DB::ExtendedLogMessage & msg_ext, std::string & text) const;
|
virtual void formatExtended(const DB::ExtendedLogMessage & msg_ext, std::string & text) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool color;
|
bool color;
|
||||||
|
Loading…
Reference in New Issue
Block a user