- Code: Select all
namespace
{
string format_name_pattern (const string & pattern)
{
string formatted;
Poco::PatternFormatter (pattern).format (Poco::Message(), formatted);
return formatted;
}
}
struct FileChannelWithPattern : Poco::FileChannel
{
FileChannelWithPattern()
{}
FileChannelWithPattern (const string & pattern)
: Poco::FileChannel (format_name_pattern (pattern))
{}
virtual void setProperty(const std::string& name, const std::string& value)
{
if (name == "path") {
FileChannel::setProperty ("path", format_name_pattern (value));
}
else {
FileChannel::setProperty (name, value);
}
}
};
// Somewhere else :
// Poco::LoggingFactory::defaultFactory().registerChannelClass ("FileChannelWithPattern", new FileChannelWithPatternFactory);
This allow me to have dynamic file names :
logging.loggers.root.channel.path = ./log/MyApp_%Y-%m-%d_%Hh%Mm%Ss_%N_%P.log
You can fill your dummy Poco::Message() with runtime attributes if needed, but I failed to see how that would be available by default in the LoggingFactory.
Anyway, maybe this FileChannelWithPattern could jump into Poco.
PS: It does not play well with archive/rotation, I guess, but I still find that useful.





