Overview
Features
Download
Documentation
Community
Add-Ons & Services

FileChannel with pattern path

Discussion of ideas for features and new projects based on POCO.

FileChannel with pattern path

Postby ilelann » 07 Nov 2012, 18:34

I added something like this in my code :

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.
ilelann
 
Posts: 1
Joined: 07 Nov 2012, 18:18

Return to Wishlist

Who is online

Users browsing this forum: Baidu [Spider] and 2 guests