Logback not creating the output logging file

Viewed 2301

I am trying to add Logback logging for my application . The code doesnt create the logging file .

I have added logback core and log back classic . Added logback.xml in resource folder . Made sure resource folder in build path .

<configuration debug="true">
 <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
     <encoder >
        <pattern>%relative [%thread] %-5level %logger{35} - %msg%n</pattern>
    </encoder>
 </appender>
 <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
     <file>/data/csrt/log_path/logFiles/logFile.log</file>
     <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
         <fileNamePattern>/data/csrt/log_path/logFiles/logFile.%d{yyyy-MM-dd-HH-mm}.log</fileNamePattern>
         <maxHistory>30</maxHistory>
         <totalSizeCap>1GB</totalSizeCap>
     </rollingPolicy>
    <encoder >
        <pattern>%relative [%thread] %-5level %logger{35} - %msg%n</pattern>
    </encoder>
 </appender>
 <root level="INFO">
     <appender-ref ref="STDOUT" />
     <appender-ref ref="FILE" />
 </root>
</configuration>

Java code:

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class MainVerticle extends AbstractVerticle {

    private static final Logger LOGGER = LoggerFactory.getLogger(MainVerticle.class);

I am expecting a log file to get created in each of the runs. It is not happening

2 Answers

log file is created lazily, please try to add an actual log statement, such as:

LOGGER.info("test");

Are you actually logging something? Just creating a Logger object isn't going to produce any output or create any log files. You have to actually call LOGGER.info/warn/error() to get any logging to occur.

If you ARE calling LOGGER.info/warn/error() elsewhere in the code in your MainVerticle class, and so that's not the problem, make sure that your program is running as a user that has the rights to write to the log location you are specifying. Also, I don't think that RollingFileAppender will create directories, so make sure that the directory into which you want to write the log file to be written actually exists.

You also create a log sink to log to the console (thanks for extending your question to show us your logback.xml file). Are you seeing logging to the console? If not, then you know that the problem has nothing to do with file I/O, or the file path or anything like that, as you're not getting logging at all.

Related