Overview
Features
Download
Documentation
Community
Add-Ons & Services

Logging framework issues

Please post support and help requests here.

Logging framework issues

Postby Felipe » 14 May 2013, 16:10

Hello.

I'm facing some problems when using the Logging Framework. I have a configuration file as following:

Code: Select all
# 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:

Code: Select all
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:

Code: Select all
Logger& subsystem1Logger = Logger::get("core.Subsystem1");
Logger& subsystem2Logger = 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 don't understand, because it is stated in the header file of the 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
Felipe
 
Posts: 6
Joined: 16 Nov 2012, 15:44

Re: Logging framework issues

Postby guenter » 15 May 2013, 22:57

Since in your case multiple loggers share the same channel, any change to that channel affects all loggers. If you don't want that you'll have to define a separate channel for each logger.
guenter
 
Posts: 1130
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: Logging framework issues

Postby Felipe » 16 May 2013, 22:18

guenter wrote:Since in your case multiple loggers share the same channel, any change to that channel affects all loggers. If you don't want that you'll have to define a separate channel for each logger.

Ok, I can do that. But I was thinking I was doing something wrong or had found a bug, since the documentation from http://pocoproject.org/slides/110-Logging.pdf states the following:
Once a logger has been fully created, it is no longer related to its ancestor. In other words, changes to log level or channel of a logger have no effect on its already existing descendants.

And the header file:
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
Felipe
 
Posts: 6
Joined: 16 Nov 2012, 15:44

Re: Logging framework issues

Postby guenter » 18 May 2013, 10:30

What the documentation says is that if you assign another channel to a logger lower in the hierarchy, descendant loggers will not automatically inherit this new channel. However, if you change the properties of a channel, all loggers using that channel will be affected by it.
guenter
 
Posts: 1130
Joined: 11 Jul 2006, 16:27
Location: Austria


Return to Support

Who is online

Users browsing this forum: No registered users and 1 guest

cron