diff --git a/libs/libdaemon/include/daemon/OwnPatternFormatter.h b/libs/libdaemon/include/daemon/OwnPatternFormatter.h index 4e356b97ddf..69ce990a569 100644 --- a/libs/libdaemon/include/daemon/OwnPatternFormatter.h +++ b/libs/libdaemon/include/daemon/OwnPatternFormatter.h @@ -7,6 +7,9 @@ #include #include +#include +#include + /** Форматирует по своему. * Некоторые детали невозможно получить, используя только 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; }; diff --git a/libs/libdaemon/src/BaseDaemon.cpp b/libs/libdaemon/src/BaseDaemon.cpp index 68a48e949c9..30d28e171e3 100644 --- a/libs/libdaemon/src/BaseDaemon.cpp +++ b/libs/libdaemon/src/BaseDaemon.cpp @@ -540,7 +540,7 @@ void BaseDaemon::buildLoggers() Poco::AutoPtr split = new SplitterChannel; // set up two channel chains - Poco::AutoPtr pf = new OwnPatternFormatter(*this); + Poco::AutoPtr pf = new OwnPatternFormatter(this); pf->setProperty("times", "local"); Poco::AutoPtr 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 level = new Poco::LevelFilterChannel; level->setLevel(Message::PRIO_NOTICE); - Poco::AutoPtr pf = new OwnPatternFormatter(*this); + Poco::AutoPtr pf = new OwnPatternFormatter(this); pf->setProperty("times", "local"); Poco::AutoPtr 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 pf = new OwnPatternFormatter(*this, OwnPatternFormatter::ADD_LAYER_TAG); + Poco::AutoPtr pf = new OwnPatternFormatter(this, OwnPatternFormatter::ADD_LAYER_TAG); pf->setProperty("times", "local"); Poco::AutoPtr 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 file = new ConsoleChannel; - Poco::AutoPtr pf = new OwnPatternFormatter(*this); + Poco::AutoPtr pf = new OwnPatternFormatter(this); pf->setProperty("times", "local"); Poco::AutoPtr log = new FormattingChannel(pf); log->setChannel(file);