i'm trying to save the log of a process to a file. This works fine when I run the class in netbeans, but after I export the JAR file there is no way the process pick the logback.xml.
The jar file is in the same path than logback.xml. I've tried using all the examples i've found here:
Using the command line file:
java -Dlogback.configurationFile=logback.xml test.jar
Setting the classpath:
java =cp "./" -jar test.jar
This is the configuration file:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<!--<Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} %M:%L- %msg%n</Pattern> -->
<Pattern>%d{HH:mm:ss.SSS} %-5level %logger{36} %M:%L - %msg%n
</Pattern>
<!--<Pattern>%d{dd/MM/yyyy HH:mm:ss.SSS} [%thread] %-5level %C{0}:%L -
%msg%n</Pattern> -->
</encoder>
</appender>
<appender name="FILE"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>test.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- daily rollover -->
<fileNamePattern>test.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- keep 30 days' worth of history -->
<maxHistory>30</maxHistory>
</rollingPolicy>
<encoder>
<!--<pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern> -->
<pattern>%d{dd/MM/yyyy HH:mm:ss.SSS} [%thread] %-5level %C{0}:%L -
%msg%n</pattern>
</encoder>
</appender>
<root level="DEBUG">
<appender-ref ref="FILE" />
<appender-ref ref="STDOUT" />
</root>
</configuration>
Please help! Thanks
I found the problem:
I had logback.*.jar and slf4j-api-simple-1.7.12.jar in my classpath. So It was using simple instead of logback.
I deleted simple, now works perfect.
thanks!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With