mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 23:21:59 +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.
|
||||
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>
|
||||
|
||||
<!-- 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")
|
||||
{
|
||||
Poco::AutoPtr<OwnPatternFormatter> pf;
|
||||
if (config().has("logger.json"))
|
||||
if (config().getString("logger.formatting", "") == "json")
|
||||
pf = new OwnJSONPatternFormatter;
|
||||
else
|
||||
pf = new OwnPatternFormatter(true);
|
||||
|
@ -99,7 +99,7 @@ void Loggers::buildLoggers(Poco::Util::AbstractConfiguration & config, Poco::Log
|
||||
|
||||
Poco::AutoPtr<OwnPatternFormatter> pf;
|
||||
|
||||
if (config.has("logger.json"))
|
||||
if (config.getString("logger.formatting", "") == "json")
|
||||
pf = new OwnJSONPatternFormatter;
|
||||
else
|
||||
pf = new OwnPatternFormatter(true);
|
||||
@ -140,7 +140,7 @@ void Loggers::buildLoggers(Poco::Util::AbstractConfiguration & config, Poco::Log
|
||||
|
||||
Poco::AutoPtr<OwnPatternFormatter> pf;
|
||||
|
||||
if (config.has("logger.json"))
|
||||
if (config.getString("logger.formatting", "") == "json")
|
||||
pf = new OwnJSONPatternFormatter;
|
||||
else
|
||||
pf = new OwnPatternFormatter(true);
|
||||
@ -184,7 +184,7 @@ void Loggers::buildLoggers(Poco::Util::AbstractConfiguration & config, Poco::Log
|
||||
|
||||
Poco::AutoPtr<OwnPatternFormatter> pf;
|
||||
|
||||
if (config.has("logger.json"))
|
||||
if (config.getString("logger.formatting", "") == "json")
|
||||
pf = new OwnJSONPatternFormatter;
|
||||
else
|
||||
pf = new OwnPatternFormatter(true);
|
||||
@ -211,7 +211,7 @@ void Loggers::buildLoggers(Poco::Util::AbstractConfiguration & config, Poco::Log
|
||||
}
|
||||
|
||||
Poco::AutoPtr<OwnPatternFormatter> pf;
|
||||
if (config.has("logger.json"))
|
||||
if (config.getString("logger.formatting", "") == "json")
|
||||
pf = new OwnJSONPatternFormatter;
|
||||
else
|
||||
pf = new OwnPatternFormatter(color_enabled);
|
||||
|
@ -1,20 +1,17 @@
|
||||
#include "OwnFormattingChannel.h"
|
||||
#include "OwnJSONPatternFormatter.h"
|
||||
#include "OwnPatternFormatter.h"
|
||||
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
void OwnFormattingChannel::logExtended(const ExtendedLogMessage & msg)
|
||||
{
|
||||
if (pChannel && priority >= msg.base.getPriority())
|
||||
{
|
||||
if (pFormatter)
|
||||
{
|
||||
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);
|
||||
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::FormatSettings settings;
|
||||
char key_name[] = "a placeholder for key names in structured logging";
|
||||
char empty_string[] = "";
|
||||
|
||||
const Poco::Message & msg = msg_ext.base;
|
||||
DB::writeChar('{', wb);
|
||||
|
||||
strcpy(key_name, "date_time");
|
||||
writeJSONString(key_name, key_name + strlen(key_name), wb, settings);
|
||||
writeJSONString("date_time", wb, settings);
|
||||
DB::writeChar(':', wb);
|
||||
|
||||
DB::writeChar('\"', wb);
|
||||
@ -42,20 +39,14 @@ void OwnJSONPatternFormatter::formatExtended(const DB::ExtendedLogMessage & msg_
|
||||
|
||||
DB::writeChar(',', wb);
|
||||
|
||||
strcpy(key_name, "thread_name");
|
||||
writeJSONString(key_name, key_name + strlen(key_name), wb, settings);
|
||||
writeJSONString("thread_name", wb, settings);
|
||||
DB::writeChar(':', wb);
|
||||
|
||||
const char * thread_name = msg.getThread().c_str();
|
||||
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);
|
||||
writeJSONString(msg.getThread(), wb, settings);
|
||||
|
||||
DB::writeChar(',', wb);
|
||||
|
||||
strcpy(key_name, "thread_id");
|
||||
writeJSONString(key_name, key_name + strlen(key_name), wb, settings);
|
||||
writeJSONString("thread_id", wb, settings);
|
||||
DB::writeChar(':', wb);
|
||||
DB::writeChar('\"', wb);
|
||||
DB::writeIntText(msg_ext.thread_id, wb);
|
||||
@ -63,65 +54,38 @@ void OwnJSONPatternFormatter::formatExtended(const DB::ExtendedLogMessage & msg_
|
||||
|
||||
DB::writeChar(',', wb);
|
||||
|
||||
strcpy(key_name, "level");
|
||||
writeJSONString(key_name, key_name + strlen(key_name), wb, settings);
|
||||
writeJSONString("level", wb, settings);
|
||||
DB::writeChar(':', wb);
|
||||
int priority_int = static_cast<int>(msg.getPriority());
|
||||
String priority_str = std::to_string(priority_int);
|
||||
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);
|
||||
|
||||
int priority = static_cast<int>(msg.getPriority());
|
||||
writeJSONString(std::to_string(priority), wb, settings);
|
||||
DB::writeChar(',', wb);
|
||||
|
||||
/// We write query_id even in case when it is empty (no query context)
|
||||
/// just to be convenient for various log parsers.
|
||||
|
||||
strcpy(key_name, "query_id");
|
||||
writeJSONString(key_name, key_name + strlen(key_name), wb, settings);
|
||||
writeJSONString("query_id", wb, settings);
|
||||
DB::writeChar(':', wb);
|
||||
writeJSONString(msg_ext.query_id, wb, settings);
|
||||
|
||||
DB::writeChar(',', wb);
|
||||
|
||||
strcpy(key_name, "logger_name");
|
||||
writeJSONString(key_name, key_name + strlen(key_name), wb, settings);
|
||||
writeJSONString("logger_name", wb, settings);
|
||||
DB::writeChar(':', wb);
|
||||
|
||||
const char * logger_name = msg.getSource().c_str();
|
||||
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);
|
||||
|
||||
writeJSONString(msg.getSource(), wb, settings);
|
||||
DB::writeChar(',', wb);
|
||||
|
||||
strcpy(key_name, "message");
|
||||
writeJSONString(key_name, key_name + strlen(key_name), wb, settings);
|
||||
writeJSONString("message", wb, settings);
|
||||
DB::writeChar(':', wb);
|
||||
const char * msg_text = msg.getText().c_str();
|
||||
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);
|
||||
|
||||
writeJSONString(msg.getText(), wb, settings);
|
||||
DB::writeChar(',', wb);
|
||||
|
||||
strcpy(key_name, "source_file");
|
||||
writeJSONString(key_name, key_name + strlen(key_name), wb, settings);
|
||||
writeJSONString("source_file", wb, settings);
|
||||
DB::writeChar(':', wb);
|
||||
const char * source_file = msg.getSourceFile();
|
||||
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);
|
||||
|
||||
writeJSONString(msg.getSourceFile(), wb, settings);
|
||||
DB::writeChar(',', wb);
|
||||
|
||||
strcpy(key_name, "source_line");
|
||||
writeJSONString(key_name, key_name + strlen(key_name), wb, settings);
|
||||
writeJSONString("source_line", wb, settings);
|
||||
DB::writeChar(':', wb);
|
||||
DB::writeChar('\"', wb);
|
||||
DB::writeIntText(msg.getSourceLine(), wb);
|
||||
|
@ -28,5 +28,5 @@ public:
|
||||
OwnJSONPatternFormatter();
|
||||
|
||||
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
|
||||
{
|
||||
DB::WriteBufferFromString wb(text);
|
||||
|
@ -25,10 +25,9 @@ class OwnPatternFormatter : public Poco::PatternFormatter
|
||||
{
|
||||
public:
|
||||
OwnPatternFormatter(bool color_ = false);
|
||||
OwnPatternFormatter();
|
||||
|
||||
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:
|
||||
bool color;
|
||||
|
Loading…
Reference in New Issue
Block a user