FileChannel with pattern path

Discussion of ideas for features and new projects based on POCO.
Posts: 1
Joined: 07 Nov 2012, 18:18

FileChannel with pattern path

Postby ilelann » 07 Nov 2012, 18:34

I added something like this in my code :

Code: Select all

    string format_name_pattern (const string & pattern)
        string formatted;
        Poco::PatternFormatter (pattern).format (Poco::Message(), formatted);
        return formatted;

struct FileChannelWithPattern : Poco::FileChannel

    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 : = ./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.

Return to “Wishlist”

Who is online

Users browsing this forum: No registered users and 0 guests