28 June 2010

additivity="false" , log4j,logback,slf4j

On your log4j.xml or logback.xml , you can at most put 2 property near your logger definitions iff it is not root logger.(except level property) (Root logger does not take name , and additivity parameters.)

name is the name of logger, where you take when you initialize factory.

private static Logger loggerName = LoggerFactory.getLogger("XX.YY");

second property is additivity and i will mention about its importance.

this is very important.

When you are logging , your logs goes into two appenders ,

one: the specified appender
second: the root appender.

if this is the case you want , leave it out, since default additivity value is true and this makes your log write both root and specified logger.

But if you you do not want it to write root appender, (you do not want your log to write twice.)

Then place additivity false yo tour logger.

Your log will only write the specified logger. And you will gain 3-8 ms. for each.

Be careful on spelling.

True format is;

logger name="loggerName" additivity="false"



Do not write aditivity , :) it is additivity.

(I am insisting on it, since official logback site also has this defect. :))


Configuring Loggers, or the element

A logger is configured using the logger element. A logger element takes exactly one mandatory name attribute, an optional level attribute, and an optional aditivity attribute, which admits the values true or false. The value of the level attribute can be one of the case-insensitive strings TRACE, DEBUG, INFO, WARN, ERROR, ALL or OFF. The special case-insensitive value INHERITED, or its synonym NULL, will force the level of the logger to be inherited from higher up in the hierarchy. This comes in handy in case you set the level of a logger and later decide that it should inherit its level.

The logger element may contain zero or more appender-ref elements; each appender thus referenced is added to the named logger. It is important to keep mind that each named logger that is declared with a

No comments: