Reputation: 292
I'm using logback in my project and it doesn't log into a file.
My logback.xml looks like this
<property file="api.properties"/>
<appender name="FILE-AUDIT"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>c:/debug.log</file>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>
%d{yyyy-MM-dd HH:mm:ss} - %msg%n
</Pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- rollover daily -->
<fileNamePattern>c:/archived/debug.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>10MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
</appender>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{5} - %msg%n</pattern>
</encoder>
</appender>
<logger name="JDBC" level="INFO" additivity="false">
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE-AUDIT" />
</logger>
<logger name="RESTSecurity" level="INFO" additivity="false">
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE-AUDIT" />
</logger>
<logger name="models" level="INFO" additivity="false">
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE-AUDIT" />
</logger>
<!-- Strictly speaking, the level attribute is not necessary since -->
<!-- the level of the root level is set to DEBUG by default. -->
<root level="DEBUG">
<appender-ref ref="STDOUT" />
</root>
and it's placed in WEB-INF/classes.
I use these dependencies
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>${logback.version}</version>
</dependency>
When I run my app on WebLogic server I get my log messages in the console but it doesn't create log files. Anyone know what could be wrong?
EDIT: I tried using both
private static final Logger logger = LoggerFactory.getLogger("JDBC");
and
private static final Logger logger = LoggerFactory.getLogger(Roles.class);
as that class is in JDBC package. Then I just do
logger.info("Initializing roles");
EDIT2: Because log messages i get in console looks different from what is in logback.xml it looks like it does ignore my logback.xml at all.
Upvotes: 1
Views: 1452
Reputation: 1377
The problem must come from Weblogic which does not pick up SLF4J/Logback from your classpath.
Add the following prefer-application-packages
to your weblogic.xml
:
<prefer-application-packages>
<package-name>org.slf4j.*</package-name>
<package-name>ch.qos.logback.*</package-name>
</prefer-application-packages>
Upvotes: 1
Reputation: 3546
You have to add all the appenders to the log level, if you want DEBUG to log to file, add the ref like this:
<root level="DEBUG">
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE-AUDIT" />
</root>
Upvotes: 0