Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logback FileAppender - logfile is empty?

In a project I have the following on the classpath:

Bundle-ClassPath: .,
 lib/logback-classic.jar,
 lib/logback-core.jar,
 lib/slf4j-api.jar

and the following in the build.properties:

bin.includes = META-INF/,\
               .,\
               plugin.xml,\
               lib/logback-classic.jar,\
               lib/logback-core.jar,\
               lib/slf4j-api.jar,\
               logback.xml

In the root I also have a logback.xml file containing:

<!--   <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> -->
<!--     <layout class="ch.qos.logback.classic.PatternLayout"> -->
<!--       <Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n -->
<!--       </Pattern> -->
<!--     </layout> -->
<!--   </appender> -->
  <root level="debug">
    <appender-ref ref="STDOUT" />
  </root>
  <appender name="FILE" class="ch.qos.logback.core.FileAppender">
    <File>logs\\logfile.log</File>
    <Append>true</Append>
    <layout class="ch.qos.logback.classic.PatternLayout">
      <Pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n
      </Pattern>
    </layout>
  </appender>
</configuration>

In a class that gets executed at startup I have:

  private static final Logger logger = LoggerFactory.getLogger(Application.class.getName());
  public Object start(IApplicationContext context) {
    logger.debug("debug string");
    logger.warn("warn string");
    logger.error("error string");

When I build and run my application a file logs\logfile.log is created in the root of my application but its empty. If I use the ConsoleAppender and enable the console it works fine.

Why does logback not write to the logfile when using the FileAppender?

like image 848
u123 Avatar asked Feb 28 '12 09:02

u123


People also ask

How do I enable debug in Logback?

debug=true to enable debugging of the logback setup. Unfortunately, there is no way to enable debugging via a System property. You have to use <configuration debug="true"> in the logback.

Where is the Logback xml file?

In a Spring Boot application, you can put the Logback. xml file in the resources folder. If your Logback. xml file is outside the classpath, you need to point to its location using the Logback.


1 Answers

Have you tried with adding file appender-ref to root in logback.xml as shown below:

<root level="debug">
   <appender-ref ref="STDOUT" />
   <appender-ref ref="FILE" />
</root>
like image 74
Girish Avatar answered Oct 12 '22 05:10

Girish