Fix logs rotation issue

This commit is contained in:
Nikolay Degterinsky 2022-07-25 13:53:27 +00:00
parent 466fceb3ee
commit c4b72277df
4 changed files with 27 additions and 0 deletions

View File

@ -1018,6 +1018,14 @@ void BaseDaemon::setupWatchdog()
logger().setChannel(log); logger().setChannel(log);
} }
/// Cuncurrent writing logs to the same file from two threads is questionable on its own,
/// but rotating them from two threads is disastrous.
if (auto * channel = dynamic_cast<DB::OwnSplitChannel *>(logger().getChannel()))
{
channel->setChannelProperty("log", Poco::FileChannel::PROP_ROTATION, "never");
channel->setChannelProperty("log", Poco::FileChannel::PROP_ROTATEONOPEN, "false");
}
logger().information(fmt::format("Will watch for the process with pid {}", pid)); logger().information(fmt::format("Will watch for the process with pid {}", pid));
/// Forward signals to the child process. /// Forward signals to the child process.

View File

@ -38,6 +38,12 @@ public:
pChannel->close(); pChannel->close();
} }
void setProperty(const std::string& name, const std::string& value) override
{
if (pChannel)
pChannel->setProperty(name, value);
}
void log(const Poco::Message & msg) override; void log(const Poco::Message & msg) override;
void logExtended(const ExtendedLogMessage & msg) override; void logExtended(const ExtendedLogMessage & msg) override;

View File

@ -169,4 +169,14 @@ void OwnSplitChannel::setLevel(const std::string & name, int level)
} }
} }
void OwnSplitChannel::setChannelProperty(const std::string& channel_name, const std::string& name, const std::string& value)
{
auto it = channels.find(channel_name);
if (it != channels.end())
{
if (auto * channel = dynamic_cast<DB::OwnFormattingChannel *>(it->second.first.get()))
channel->setProperty(name, value);
}
}
} }

View File

@ -24,6 +24,9 @@ class OwnSplitChannel : public Poco::Channel
public: public:
/// Makes an extended message from msg and passes it to the client logs queue and child (if possible) /// Makes an extended message from msg and passes it to the client logs queue and child (if possible)
void log(const Poco::Message & msg) override; void log(const Poco::Message & msg) override;
void setChannelProperty(const std::string& channel_name, const std::string& name, const std::string& value);
/// Adds a child channel /// Adds a child channel
void addChannel(Poco::AutoPtr<Poco::Channel> channel, const std::string & name); void addChannel(Poco::AutoPtr<Poco::Channel> channel, const std::string & name);