How to log messages from different packages to different appenders with logback

I am trying to log messages from third party libraries to different file with the below logback extract <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> <encoder> <pattern>%d{HH:mm:ss.SSS} %-5level [%.45(%thread)][%.32(%logger{32})] %msg%n</pattern> </encoder> </appender> <timestamp key="byDay" datePattern="yyyyMMdd'T'HHmmss"/> <appender name="FILE" class="ch.qos.logback.core.FileAppender"> <file>F:\v1\devel\logs\app-${byDay}.txt </file> <append>true</append> <encoder> <pattern>%d{HH:mm:ss.SSS} %-5level [%.45(%thread)][%.32(%logger{32})] %msg%n</pattern> </encoder> </appender> <!-- ALL: INFO level --> <root level="INFO"> <appender-ref ref="CONSOLE"/> </root> <!-- Third-party: some reduced levels --> <logger name="org.hibernate" level="TRACE" additivity="false"> <appender-ref ref="FILE"/> </logger> I want hibernate TRACE level logs to be logged to a file while other INFO messages should go to the console. The above xml config isn't working for me. Nothing gets logged to the file. Any suggestions? Thanks, Amit

I'm not positive but you might have to set additivity="true" (the default) for your "org.hibernate" logger so that both it and the root logger can process the message. With additivity="false" only the most specific logger match will process the message. (*Chris*) On Tue, Jul 21, 2015 at 5:52 AM, amit shah <amits.84@gmail.com> wrote:
I am trying to log messages from third party libraries to different file with the below logback extract
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> <encoder> <pattern>%d{HH:mm:ss.SSS} %-5level [%.45(%thread)][%.32(%logger{32})] %msg%n</pattern> </encoder> </appender>
<timestamp key="byDay" datePattern="yyyyMMdd'T'HHmmss"/>
<appender name="FILE" class="ch.qos.logback.core.FileAppender"> <file>F:\v1\devel\logs\app-${byDay}.txt </file> <append>true</append> <encoder> <pattern>%d{HH:mm:ss.SSS} %-5level [%.45(%thread)][%.32(%logger{32})] %msg%n</pattern> </encoder> </appender>
<!-- ALL: INFO level --> <root level="INFO"> <appender-ref ref="CONSOLE"/> </root>
<!-- Third-party: some reduced levels --> <logger name="org.hibernate" level="TRACE" additivity="false"> <appender-ref ref="FILE"/> </logger>
I want hibernate TRACE level logs to be logged to a file while other INFO messages should go to the console. The above xml config isn't working for me. Nothing gets logged to the file.
Any suggestions?
Thanks, Amit
_______________________________________________ Logback-user mailing list Logback-user@qos.ch http://mailman.qos.ch/mailman/listinfo/logback-user

No. Making additivity as true didn't help. The log file didn't have any messages logged (0 KB). Any other suggestions? On Wed, Jul 22, 2015 at 1:56 AM, Chris Pratt <thechrispratt@gmail.com> wrote:
I'm not positive but you might have to set additivity="true" (the default) for your "org.hibernate" logger so that both it and the root logger can process the message. With additivity="false" only the most specific logger match will process the message. (*Chris*)
On Tue, Jul 21, 2015 at 5:52 AM, amit shah <amits.84@gmail.com> wrote:
I am trying to log messages from third party libraries to different file with the below logback extract
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> <encoder> <pattern>%d{HH:mm:ss.SSS} %-5level [%.45(%thread)][%.32(%logger{32})] %msg%n</pattern> </encoder> </appender>
<timestamp key="byDay" datePattern="yyyyMMdd'T'HHmmss"/>
<appender name="FILE" class="ch.qos.logback.core.FileAppender"> <file>F:\v1\devel\logs\app-${byDay}.txt </file> <append>true</append> <encoder> <pattern>%d{HH:mm:ss.SSS} %-5level [%.45(%thread)][%.32(%logger{32})] %msg%n</pattern> </encoder> </appender>
<!-- ALL: INFO level --> <root level="INFO"> <appender-ref ref="CONSOLE"/> </root>
<!-- Third-party: some reduced levels --> <logger name="org.hibernate" level="TRACE" additivity="false"> <appender-ref ref="FILE"/> </logger>
I want hibernate TRACE level logs to be logged to a file while other INFO messages should go to the console. The above xml config isn't working for me. Nothing gets logged to the file.
Any suggestions?
Thanks, Amit
_______________________________________________ Logback-user mailing list Logback-user@qos.ch http://mailman.qos.ch/mailman/listinfo/logback-user
_______________________________________________ Logback-user mailing list Logback-user@qos.ch http://mailman.qos.ch/mailman/listinfo/logback-user
participants (2)
-
amit shah
-
Chris Pratt