Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Behaviour of tango.util.log.Log changed

Moderators: kris

Posted: 11/26/09 15:31:03

When I do

import  tango.util.log.Log;
import  tango.util.log.AppendConsole;
import  tango.util.log.LayoutDate;
import  tango.io.Console;

void main (char[][] args)
{
    auto rootLog  = Log.root;
    rootLog.add(new AppendStream(Cout.stream, true, new LayoutDate()));
    rootLog.level = rootLog.Info;

    auto log = Log.lookup("Test:");
    log.info("rootLog - Level = '{}'", rootLog.level);
    log.info("log     - Level = '{}'", log.level);
}

I get with tango-r5218

2009-11-26 16:15:33,266 Info [Test:] - rootLog - Level = '1'
2009-11-26 16:15:33,266 Info [Test:] - log     - Level = '0'

with an older tango (tested with tango-r4967) I got

2009-11-26 16:13:12,747 Info   Test: - rootLog - Level = '1'
2009-11-26 16:13:12,747 Info   Test: - log     - Level = '1'

The problem is the fact, that with older tango the log object inherited the log.level from the rootlog object. With new tango log doesn't inherit the level.

Has this been changed by purpose?

Author Message

Posted: 11/27/09 05:54:36

it was changed, yes, based upon this ticket: http://dsource.org/projects/tango/ticket/1514

trying to think of a good way to accommodate both approaches ... ideas?

Posted: 11/27/09 16:18:17

The ticket author says: But according to the Tango manual it should not matter in which order I create them.

The manual http://www.dsource.org/projects/tango/wiki/ChapterLogging says:

The Logger Tree

Conceptually, each Logger instantiated can be viewed as a node in a tree. When a new Logger instance is created, it is inserted into the appropriate position in the tree. The Logger at the node above the new instance becomes its parent. The new instance inherits the Level and Appender configuration of its parent. This is a powerful feature that allows entire groups of Loggers to be configured at once.

Is it posssible to inherit Level and Appender configuration of the parent only at creation time of a new logger?

Then my approach should work (again).

And the ticket author should inherit everything of the root logger upon creation of the child logger. When inserting the parent logger into the tree, the parent logger should inherit from root again. When using the child logger one more time, the child logger should see no modification according to when it was created.

Posted: 11/27/09 21:38:04

In that scenario, you'd also want the children to change when the parent is changed. That is also how it used to operate, but then that caused a ripple change when the parent was inserted too ...

Posted: 11/27/09 23:07:12

Hmmm, having reread the manual, I think the manual explicitly says that my approach should work.

The ticket author (I think) did expect to see his child logger without change after inserting the parent logger.

Anyway: IMHO the main question is, whether changes to a parent logger should modify the behaviour of the child loggers at runtime (after they have been created) or only at creation time.

So, do you want all child loggers to change their behaviour after they have been created, when you modify some parent up the tree at runtime?

Or do you want all child loggers to behave like they did, when they were created, even if some parent up the tree is changed later on?

I think, there are good reasons for both approaches and I'm not familiar with, how this is handled by the original log4j. But in my opinion this should be done, like log4j does it.

Posted: 11/27/09 23:53:06

So, do you want all child loggers to change their behaviour after they have been created, when you modify some parent up the tree at runtime?

Or do you want all child loggers to behave like they did, when they were created, even if some parent up the tree is changed later on?

Tango used to do both ;)

Posted: 11/28/09 09:33:58

Tango used to do both

Frankly, I don't understand. Both at the same time? Have there been options for the user to decide?

Actually I never did things like that (insert or modify parent loggers after creating child loggers). I always used loggers like recommended by the manual (at least how I understood it): Create root or parent logger, attach/detach Appender(s) to it, give it a default Log Level. Later on create child loggers and expect them to inherit Appenders and Log Level from their parents.

I only want my inherited Log Level back ;-)

Posted: 11/30/09 17:25:11

Tango used to do both

I apologize.

After reading some more documentation (err, not really - reading the source code made me finally understand it), I think I got what kris means.

Yes, tango does both:

parentLogger.level(parentLogger.Warn);

sets the level of the parent logger and leaves all children's levels unchanged.

parentLogger.level(parentLogger.Warn, true);

sets the level of the parent logger and enforces, that all children's levels are also changed accordingly.

Anyway, I reopened #1514 since the fix broke logging, like recommended in the manual (but I added a proposed patch).

Posted: 12/01/09 18:32:35

thanks, and I think this is fixed now :)