I'm facing some problems when using the Logging Framework. I have a configuration file as following:
# core channel
logging.channels.c1.class = FileChannel
logging.channels.c1.path = <somePath>/core.log
logging.channels.c1.archive = timestamp
logging.channels.c1.times = utc
logging.channels.c1.rotation = daily
logging.channels.c1.formatter.class = PatternFormatter
logging.channels.c1.formatter.pattern = %Y-%m-%d %H:%M:%S %s: [%p] %t
# core logger
logging.loggers.l1.name = core
logging.loggers.l1.level = information
logging.loggers.l1.channel = c1
My program uses Poco::Util:ServerApplication framework, benefiting from the subsystems schema. I have multiple subsystems, and each one stores a reference to a Poco::Logger object, obtained by using the Poco::Logger::get("logger name") method. I'm trying to use to use the log hierarchy, having the "core" log, as showed in the configuration file above, as the root of my logging hierarchy. The following code exemplifies what I'm doing in each susbsystem:
Subsystem1::Subsystem1() :
Poco::Util::Subsystem(),
logger_(Poco::Logger::get("core." + std::string(name()))),
...
Subsystem2::Subsystem2() :
Poco::Util::Subsystem(),
logger_(Poco::Logger::get("core." + std::string(name()))),
...
That works for logging. It's nice because I've inherited the configuration from the property file, and each subsystem will have a different Poco::Message source name, making it easy to identify from which subsystem the logging entry comes from.
The problem arrives when I try to change a property of an instance of a logger (for example, from Subsystem1's logger). If I change it's channel's path, for instance, the changing is propagated to the whole hierarchy. The following code demonstrate the issue:
Poco::Logger& subsystem1Logger = Poco::Logger::get("core.Subsystem1");
Poco::Logger& subsystem2Logger = Poco::Logger::get("core.Subsystem2");
subsystem1Logger.getChannel()->close(); //without this, the change to the channel's path does nothing
subsystem1Logger.getChannel()->setProperty("path", <someOtherPath>/core2.log); // Ok, it's changed
poco_information(subsystem1Logger "some message"); // Ok, it logs to <someOtherPath>/core2.log
poco_information(subsystem2Logger "some message"); // NOT OK, it also logs to <someOtherPath>/core2.log instead of <somePath>/core.log
I'm confused, because it is stated in the header file of the Poco::Logger class that "Once a logger has been created and it has inherited the channel and level from its ancestor, it loses the connection to it. So changes to the level or channel of a logger do not affect its descendants".
By the way, my root logger (core) is also affected by the change.
Am I missing something? Thanks.
Poco Library version: 1.5.1
I think you are getting confused between a logger and a channel.
The loggers Core Core.Subsystem1 Core.Subsystem2
are all attached to the same channel c1, because they are a copy of Core when they are created.
It's the channel c1 that you are changing through the Logger.getChannel() function.
If the loggers were attached to different channels then your approach would be working.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With