mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 23:21:59 +00:00
support absence of BaseDaemon in OwnPatternFormatter
This commit is contained in:
parent
fb5ff00c4a
commit
5107cd94b3
@ -7,6 +7,9 @@
|
||||
#include <DB/IO/WriteHelpers.h>
|
||||
#include <daemon/BaseDaemon.h>
|
||||
|
||||
#include <experimental/optional>
|
||||
#include <functional>
|
||||
|
||||
|
||||
/** Форматирует по своему.
|
||||
* Некоторые детали невозможно получить, используя только Poco::PatternFormatter.
|
||||
@ -30,16 +33,16 @@ public:
|
||||
ADD_LAYER_TAG = 1 << 0
|
||||
};
|
||||
|
||||
OwnPatternFormatter(const BaseDaemon & daemon_, Options options_ = ADD_NOTHING) : Poco::PatternFormatter(""), daemon(daemon_), options(options_) {}
|
||||
OwnPatternFormatter(const BaseDaemon * daemon_, Options options_ = ADD_NOTHING) : Poco::PatternFormatter(""), daemon(daemon_), options(options_) {}
|
||||
|
||||
void format(const Poco::Message & msg, std::string & text) override
|
||||
{
|
||||
DB::WriteBufferFromString wb(text);
|
||||
|
||||
/// For syslog: tag must be before message and first whitespace.
|
||||
if (options & ADD_LAYER_TAG)
|
||||
if (options & ADD_LAYER_TAG && daemon)
|
||||
{
|
||||
auto layer = daemon.getLayer();
|
||||
auto layer = daemon->getLayer();
|
||||
if (layer)
|
||||
{
|
||||
writeCString("layer[", wb);
|
||||
@ -75,6 +78,6 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
const BaseDaemon & daemon;
|
||||
const BaseDaemon * daemon;
|
||||
Options options;
|
||||
};
|
||||
|
@ -540,7 +540,7 @@ void BaseDaemon::buildLoggers()
|
||||
Poco::AutoPtr<SplitterChannel> split = new SplitterChannel;
|
||||
|
||||
// set up two channel chains
|
||||
Poco::AutoPtr<OwnPatternFormatter> pf = new OwnPatternFormatter(*this);
|
||||
Poco::AutoPtr<OwnPatternFormatter> pf = new OwnPatternFormatter(this);
|
||||
pf->setProperty("times", "local");
|
||||
Poco::AutoPtr<FormattingChannel> log = new FormattingChannel(pf);
|
||||
log_file = new FileChannel;
|
||||
@ -558,7 +558,7 @@ void BaseDaemon::buildLoggers()
|
||||
std::cerr << "Should error logs to " << config().getString("logger.errorlog") << std::endl;
|
||||
Poco::AutoPtr<Poco::LevelFilterChannel> level = new Poco::LevelFilterChannel;
|
||||
level->setLevel(Message::PRIO_NOTICE);
|
||||
Poco::AutoPtr<OwnPatternFormatter> pf = new OwnPatternFormatter(*this);
|
||||
Poco::AutoPtr<OwnPatternFormatter> pf = new OwnPatternFormatter(this);
|
||||
pf->setProperty("times", "local");
|
||||
Poco::AutoPtr<FormattingChannel> errorlog = new FormattingChannel(pf);
|
||||
error_log_file = new FileChannel;
|
||||
@ -575,7 +575,7 @@ void BaseDaemon::buildLoggers()
|
||||
|
||||
if (config().getBool("logger.use_syslog", false) || config().getBool("dynamic_layer_selection", false))
|
||||
{
|
||||
Poco::AutoPtr<OwnPatternFormatter> pf = new OwnPatternFormatter(*this, OwnPatternFormatter::ADD_LAYER_TAG);
|
||||
Poco::AutoPtr<OwnPatternFormatter> pf = new OwnPatternFormatter(this, OwnPatternFormatter::ADD_LAYER_TAG);
|
||||
pf->setProperty("times", "local");
|
||||
Poco::AutoPtr<FormattingChannel> log = new FormattingChannel(pf);
|
||||
syslog_channel = new Poco::SyslogChannel(commandName(), Poco::SyslogChannel::SYSLOG_CONS | Poco::SyslogChannel::SYSLOG_PID, Poco::SyslogChannel::SYSLOG_DAEMON);
|
||||
@ -592,7 +592,7 @@ void BaseDaemon::buildLoggers()
|
||||
{
|
||||
// Выводим на консоль
|
||||
Poco::AutoPtr<ConsoleChannel> file = new ConsoleChannel;
|
||||
Poco::AutoPtr<OwnPatternFormatter> pf = new OwnPatternFormatter(*this);
|
||||
Poco::AutoPtr<OwnPatternFormatter> pf = new OwnPatternFormatter(this);
|
||||
pf->setProperty("times", "local");
|
||||
Poco::AutoPtr<FormattingChannel> log = new FormattingChannel(pf);
|
||||
log->setChannel(file);
|
||||
|
Loading…
Reference in New Issue
Block a user