rcmadruga
rcmadruga

Reputation: 847

Using Poco library, how to set different log levels per channel in a splitter channel logger?

What I have now:

.

//Windows Event Log
Poco::EventLogChannel* elChannel = new Poco::EventLogChannel("App");

//Simple file Log
Poco::SimpleFileChannel* sfChannel = new Poco::SimpleFileChannel();
sfChannel->setProperty("path", "log.txt");
sfChannel->setProperty("rotation", "10 M");

//Splitter Channel 
Poco::SplitterChannel* sChannel = new Poco::SplitterChannel();
sChannel->addChannel(sfChannel);
sChannel->addChannel(elChannel);

logger().root().setChannel(sChannel);
logger().root().setLevel(Poco::Message::PRIO_INFORMATION);

I would like to have different log levels per channel in the splitter:

This way only messages above WARNING would go to Windows Event Viewer.

Could this be achieved in some way using standard Poco::Logger?

Upvotes: 2

Views: 3315

Answers (2)

Vencat
Vencat

Reputation: 1622

Here is a simple example.

#include "Poco/Logger.h"
using Poco::Logger;
int main(int argc, char** argv)
{
    Logger& logger = Logger::get("TestLogger");
    logger.information("This is an informational message");
    logger.warning("This is a warning message");
    return 0;
}

More details:

https://pocoproject.org/slides/110-Logging.pdf

Here are some valuable slides about other Poco subsystems

https://pocoproject.org/slides/

I hope the links won't be broken :)

Upvotes: 0

Alex
Alex

Reputation: 5330

Logging level is per Logger, not per Channel, so you will have to have two loggers. See Logger example. To avoid inconvenience of having to log the same thing twice, you can write your own "splitter" function that wraps the loggers and logs the same messages to both.

Upvotes: 2

Related Questions