You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Luigi Alice <Lu...@persis.de> on 2013/09/18 13:11:26 UTC
Log level issue with multiple loggers
Hello,
I want to log to two different files, each file with different log levels.
Firstly, I defined the root logger with Level ERROR which is writing to file number "1".
Then the second logger with special Logger-Name "1292B83C9F81DAB40710C063C441A641.P011Tomcat60001" should log to file number "2" with Level ALL.
The problem is:
Log-Level entries in file "2" with the level of WARN and above are also logged to file "1".
But there must only be ERROR-Messages in file "1".
I don't want to use additivity="false" because file 1 is the global logger (it logs all activities) and file 2 is only a user-specific logger.
I use Apache Log4j 2 Beta 9
Here is the configuration:
<?xml version="1.0" encoding="UTF-8"?>
<configuration status="debug">
<properties>
</properties>
<appenders>
<RollingFile name="RollingFile" fileName="${ctx:log.dir}/global.log"
filePattern="${ctx:log.dir}/$${date:yyyy-MM}/app-%d{MM-dd-yyyy}-%i.log">
<PatternLayout>
<pattern>[%d{HH:mm:ss.SSS}|%X{remoteAddr}:%X{session}(%X{page}%X{includeStack}#%X{taskID})|%X{levelNo}] %X{location}: %m%n</pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy />
<SizeBasedTriggeringPolicy size="10 MB"/>
</Policies>
<DefaultRolloverStrategy max="50"/>
</RollingFile>
<RollingFile name="1292B83C9F81DAB40710C063C441A641.P011Tomcat60001" fileName="${ctx:log.dir}/1292B83C9F81DAB40710C063C441A641.P011Tomcat60001/user.log"
filePattern="${ctx:log.dir}/1292B83C9F81DAB40710C063C441A641.P011Tomcat60001/user-%d{yyyy-MM-dd}-%i.log">
<PatternLayout>
<pattern>[%d{HH:mm:ss.SSS}|%X{remoteAddr}:%X{session}(%X{page}%X{includeStack}#%X{taskID})|%X{levelNo}] %X{location}: %m%n</pattern>
</PatternLayout>
<Policies>
<SizeBasedTriggeringPolicy size="10 MB"/>
</Policies>
</RollingFile>
</appenders>
<loggers>
<root level="ERROR">
<AppenderRef ref="RollingFile"/>
</root>
<logger name="1292B83C9F81DAB40710C063C441A641.P011Tomcat60001" level="ALL">
<AppenderRef ref="1292B83C9F81DAB40710C063C441A641.P011Tomcat60001"/>
</logger>
</loggers>
</configuration>
Regards
Mr. L. Alice
Software developer
______________________________
[cid:image001.png@01CEB470.94A2FF10]
Persis GmbH
Erchenstraße 12
89522 Heidenheim
Tel.: +49 7321 9884-0
Fax: +49 7321 9884-98
E-Mail: luigi.alice@persis.de<ma...@persis.de>
Web: www.persis.de<http://www.persis.de/>
______________________________
Sitz der Gesellschaft: 89522 Heidenheim
Registergericht: Ulm
Handelsregister Nr.: HRB 660674
Geschäftsführer: Rainer Kolb, Michael Barth
AW: Log level issue with multiple loggers
Posted by Luigi Alice <Lu...@persis.de>.
That's it!
I'm using this:
<loggers>
<root level="ALL">
<AppenderRef ref="RollingFile" level="INFO" />
</root>
<logger name="1292B83C9F81DAB40710C063C441A641.P011Tomcat60001" level="ALL">
<AppenderRef ref="1292B83C9F81DAB40710C063C441A641.P011Tomcat60001" level="ERROR" />
</logger>
</loggers>
By the way:
What's the difference of setting both level-attributes?
Mit freundlichen Grüßen
Herr Dipl.-Inf. L. Alice
Softwareentwicklung
-----Ursprüngliche Nachricht-----
Von: Remko Popma [mailto:remko.popma@gmail.com]
Gesendet: Mittwoch, 18. September 2013 13:39
An: Log4J Users List
Betreff: Re: Log level issue with multiple loggers
Try setting the log level on the AppenderRef of the root logger:
...
<loggers>
<root level="trace">
<AppenderRef ref="RollingFile" level="error"/>
</root>
...
On Wednesday, September 18, 2013, Luigi Alice wrote:
> Hello,****
>
> ** **
>
> I want to log to two different files, each file with different log levels.
> ****
>
> Firstly, I defined the root logger with Level ERROR which is writing
> to file number "1".****
>
> Then the second logger with special Logger-Name
> "1292B83C9F81DAB40710C063C441A641.P011Tomcat60001" should log to file
> number "2" with Level ALL.****
>
> The problem is:****
>
> Log-Level entries in file "2" with the level of WARN and above are
> also logged to file "1".****
>
> But there must only be ERROR-Messages in file "1".****
>
> I don't want to use additivity="false" because file 1 is the global
> logger (it logs all activities) and file 2 is only a user-specific
> logger.****
>
> I use Apache Log4j 2 Beta 9****
>
> ** **
>
> Here is the configuration:****
>
> ** **
>
> <?xml version="1.0" encoding="UTF-8"?>****
>
> <configuration status="debug">****
>
> <properties>****
>
> </properties>****
>
> <appenders> ****
>
> <RollingFile name="RollingFile"
> fileName="${ctx:log.dir}/global.log"****
>
>
> filePattern="${ctx:log.dir}/$${date:yyyy-MM}/app-%d{MM-dd-yyyy}-%i.log
> ">**
> **
>
> <PatternLayout>****
>
>
> <pattern>[%d{HH:mm:ss.SSS}|%X{remoteAddr}:%X{session}(%X{page}%X{inclu
> deStack}#%X{taskID})|%X{levelNo}]
> %X{location}: %m%n</pattern>****
>
> </PatternLayout>****
>
> <Policies>****
>
> <TimeBasedTriggeringPolicy />****
>
> <SizeBasedTriggeringPolicy size="10 MB"/>****
>
> </Policies>****
>
> <DefaultRolloverStrategy max="50"/>****
>
> </RollingFile> ****
>
> <RollingFile
> name="1292B83C9F81DAB40710C063C441A641.P011Tomcat60001"
> fileName="${ctx:log.dir}/1292B83C9F81DAB40710C063C441A641.P011Tomcat60001/user.log"
> ****
>
>
> filePattern="${ctx:log.dir}/1292B83C9F81DAB40710C063C441A641.P011Tomca
> t60001/user-%d{yyyy-MM-dd}-%i.log">
> ****
>
> <PatternLayout>****
>
>
> <pattern>[%d{HH:mm:ss.SSS}|%X{remoteAddr}:%X{session}(%X{page}%X{inclu
> deStack}#%X{taskID})|%X{levelNo}]
> %X{location}: %m%n</pattern>****
>
> </PatternLayout>****
>
> <Policies>****
>
> <SizeBasedTriggeringPolicy size="10 MB"/>****
>
> </Policies>****
>
> </RollingFile> ****
>
> </appenders>****
>
> <loggers> ****
>
> <root level="ERROR">****
>
> <AppenderRef ref="RollingFile"/> ****
>
> </root> ****
>
> <logger name="1292B83C9F81DAB40710C063C441A641.P011Tomcat60001"
> level="ALL"> ****
>
> <AppenderRef
> ref="1292B83C9F81DAB40710C063C441A641.P011Tomcat60001"/> ****
>
> </logger>****
>
> </loggers>****
>
> </configuration>****
>
> ** **
>
> ** **
>
> Regards****
>
> ** **
>
> Mr. L. Alice
> Software developer****
>
> ** **
>
> ______________________________****
>
> ** **
>
> ****
>
> ** **
>
> Persis GmbH****
>
> Erchenstraße 12****
>
> 89522 Heidenheim****
>
> Tel.: +49 7321 9884-0 ** **
>
> Fax: +49 7321 9884-98****
>
> E-Mail: luigi.alice@persis.de <javascript:_e({}, 'cvml',
> 'luigi.alice@persis.de');> ****
>
> Web: www.persis.de****
>
> ______________________________****
>
> ** **
>
> Sitz der Gesellschaft: 89522 Heidenheim
> Registergericht: Ulm
> Handelsregister Nr.: HRB 660674
> Geschäftsführer: Rainer Kolb, Michael Barth****
>
> ** **
>
> ** **
>
> ** **
>
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: Log level issue with multiple loggers
Posted by Remko Popma <re...@gmail.com>.
Try setting the log level on the AppenderRef of the root logger:
...
<loggers>
<root level="trace">
<AppenderRef ref="RollingFile" level="error"/>
</root>
...
On Wednesday, September 18, 2013, Luigi Alice wrote:
> Hello,****
>
> ** **
>
> I want to log to two different files, each file with different log levels.
> ****
>
> Firstly, I defined the root logger with Level ERROR which is writing to
> file number “1”.****
>
> Then the second logger with special Logger-Name
> “1292B83C9F81DAB40710C063C441A641.P011Tomcat60001” should log to file
> number “2” with Level ALL.****
>
> The problem is:****
>
> Log-Level entries in file “2” with the level of WARN and above are also
> logged to file “1”.****
>
> But there must only be ERROR-Messages in file “1”.****
>
> I don’t want to use additivity=”false” because file 1 is the global logger
> (it logs all activities) and file 2 is only a user-specific logger.****
>
> I use Apache Log4j 2 Beta 9****
>
> ** **
>
> Here is the configuration:****
>
> ** **
>
> <?xml version="1.0" encoding="UTF-8"?>****
>
> <configuration status="debug">****
>
> <properties>****
>
> </properties>****
>
> <appenders> ****
>
> <RollingFile name="RollingFile"
> fileName="${ctx:log.dir}/global.log"****
>
>
> filePattern="${ctx:log.dir}/$${date:yyyy-MM}/app-%d{MM-dd-yyyy}-%i.log">**
> **
>
> <PatternLayout>****
>
>
> <pattern>[%d{HH:mm:ss.SSS}|%X{remoteAddr}:%X{session}(%X{page}%X{includeStack}#%X{taskID})|%X{levelNo}]
> %X{location}: %m%n</pattern>****
>
> </PatternLayout>****
>
> <Policies>****
>
> <TimeBasedTriggeringPolicy />****
>
> <SizeBasedTriggeringPolicy size="10 MB"/>****
>
> </Policies>****
>
> <DefaultRolloverStrategy max="50"/>****
>
> </RollingFile> ****
>
> <RollingFile
> name="1292B83C9F81DAB40710C063C441A641.P011Tomcat60001"
> fileName="${ctx:log.dir}/1292B83C9F81DAB40710C063C441A641.P011Tomcat60001/user.log"
> ****
>
>
> filePattern="${ctx:log.dir}/1292B83C9F81DAB40710C063C441A641.P011Tomcat60001/user-%d{yyyy-MM-dd}-%i.log">
> ****
>
> <PatternLayout>****
>
>
> <pattern>[%d{HH:mm:ss.SSS}|%X{remoteAddr}:%X{session}(%X{page}%X{includeStack}#%X{taskID})|%X{levelNo}]
> %X{location}: %m%n</pattern>****
>
> </PatternLayout>****
>
> <Policies>****
>
> <SizeBasedTriggeringPolicy size="10 MB"/>****
>
> </Policies>****
>
> </RollingFile> ****
>
> </appenders>****
>
> <loggers> ****
>
> <root level="ERROR">****
>
> <AppenderRef ref="RollingFile"/> ****
>
> </root> ****
>
> <logger name="1292B83C9F81DAB40710C063C441A641.P011Tomcat60001"
> level="ALL"> ****
>
> <AppenderRef
> ref="1292B83C9F81DAB40710C063C441A641.P011Tomcat60001"/> ****
>
> </logger>****
>
> </loggers>****
>
> </configuration>****
>
> ** **
>
> ** **
>
> Regards****
>
> ** **
>
> Mr. L. Alice
> Software developer****
>
> ** **
>
> ______________________________****
>
> ** **
>
> ****
>
> ** **
>
> Persis GmbH****
>
> Erchenstraße 12****
>
> 89522 Heidenheim****
>
> Tel.: +49 7321 9884-0 ** **
>
> Fax: +49 7321 9884-98****
>
> E-Mail: luigi.alice@persis.de <javascript:_e({}, 'cvml',
> 'luigi.alice@persis.de');> ****
>
> Web: www.persis.de****
>
> ______________________________****
>
> ** **
>
> Sitz der Gesellschaft: 89522 Heidenheim
> Registergericht: Ulm
> Handelsregister Nr.: HRB 660674
> Geschäftsführer: Rainer Kolb, Michael Barth****
>
> ** **
>
> ** **
>
> ** **
>