Logging to multiple targets at different LogSetupLevels

78 views
Skip to first unread message

Mike Partridge

unread,
Feb 27, 2013, 2:34:01 PM2/27/13
to as3-commons...@googlegroups.com
First I'd like to say that as3-commons-logging has simplified logging in my project, and the user guide and documentation are very good, so thanks very much!

I'm trying to log to a couple of different custom ILogTarget implementations at different LogSetupLevels, but it looks like my log messages aren't going to both targets. I'm configuring logging with the following code:

var localTargetSetup:LevelTargetSetup = new LevelTargetSetup(
new ExternalInterfaceTarget(), 
LogSetupLevel.DEBUG
);
var serverTargetSetup:LevelTargetSetup = new LevelTargetSetup(
new FunctionTarget(this.serverLog), 
LogSetupLevel.INFO
);
LOGGER_FACTORY.setup = new MergedSetup(localTargetSetup, serverTargetSetup);

My intention with this code is to have all log messages hit the ExternalInterfaceTarget, and only INFO and higher to hit the FunctionTarget (which works), but only DEBUG messages are hitting the ExternalInterfaceTarget. If I change my serverTargetSetup to:

var serverTargetSetup:LevelTargetSetup = new LevelTargetSetup(
new FunctionTarget(this.serverLog), 
LogSetupLevel.DEBUG
);

I don't get any log messages at all hitting my ExternalInterfaceTarget. Is it possible to do this? Am I making this more complicated than necessary?

martin heidegger

unread,
Feb 27, 2013, 9:33:23 PM2/27/13
to as3-commons...@googlegroups.com

LevelTargetSetup is a primitive mechanism that basically sets the target for each passed in logger to a value.

See LogSetupLevel#applyTo


It doesn't check (and merge) If the logger for that particular level has already been set, it just overrides it. A big aspect of the performance of this framework is that there can be only one target per logger.

In your case you can either merge the targets (not the setups) to have them both applied to debug like this:

var externalTarget = new ExternalInterfaceTarget();
var serverTarget = new FunctionTarget(this.serverLog);

LOGGER_FACTORY.setup = new LevelTargetSetup(
    mergeTargets(externalTarget, serverTarget),
    LogSetupLevel.DEBUG
);

and if you want to have them added for info as well use:

LOGGER_FACTORY.setup = mergeSetups(
    new LevelTargetSetup(externalTarget, LogSetupLevel.DEBUG),
    new LevelTargetSetup(mergeTargets(externalTarget, serverTarget), LogSetupLevel.INFO)
);

this way the logging system will push only the externalTarget to the debug level but then overwrite everything from INFO with a mergedTarget.

However: This tends to become a little cluttered over time and hard to decipher so I recommend using the log4j setup style once you exceeded a certain size as it will be just easier to read ;)


yours
Martin.

--
You received this message because you are subscribed to the Google Groups "as3-commons-developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to as3-commons-devel...@googlegroups.com.
To post to this group, send email to as3-commons...@googlegroups.com.
Visit this group at http://groups.google.com/group/as3-commons-developers?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Mike Partridge

unread,
Feb 28, 2013, 3:10:49 PM2/28/13
to as3-commons...@googlegroups.com
I understand the reasoning behind binding each level to a single logger, but in my case I need DEBUG messages to be logged in two different ways, so I ended up creating a custom ILogTarget that does both.

Thanks very much for your help, Martin!
Martin.

To unsubscribe from this group and stop receiving emails from it, send an email to as3-commons-developers+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages