[logback-dev] Logback doesn't write to a log file

Sara J sarajuspt at gmail.com
Wed Aug 24 05:38:05 UTC 2016


Hello,

I am trying to migrating my code from log4j to logback without changing my
code using log4j-over-slfj.jar
The logger files creates successefully  but nothing  is written in the log
files/console

*I added the following dependencies in my pom file:*

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.21</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>1.7.21</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.1.7</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.7</version>
</dependency>

*This is my logback.xml:*

<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="true">
   <property name="USER_HOME" value="c:\\temp" />
   <property name="ENV_PREFIX" value="s1" />
 <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{36} -
%msg%n</pattern>
    </encoder>
  </appender>
<appender name="COM_FILE"
class="ch.qos.logback.core.rolling.RollingFileAppender">
      <file>${USER_HOME}\comFile-${ENV_PREFIX}.log</file>
      <rollingPolicy
class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">

 <fileNamePattern>${USER_HOME}\comFile-${ENV_PREFIX}.%i.log</fileNamePattern>
         <minIndex>1</minIndex>
         <maxIndex>5</maxIndex>
      </rollingPolicy>
      <triggeringPolicy
class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
         <maxFileSize>50MB</maxFileSize>
      </triggeringPolicy>
      <encoder>
         <pattern>%d [%t] %-3p - ID:%X{UUID} %m%n</pattern>
      </encoder>
   </appender>
   <appender name="ASYNC_COM_FILE"
class="ch.qos.logback.classic.AsyncAppender">
      <appender-ref ref="COM_FILE" />
   </appender>
   <appender name="transactionLoggerData"
class="ch.qos.logback.core.rolling.RollingFileAppender">
 <file>${USER_HOME}\transaction-${ENV_PREFIX}.log</file>
 <rollingPolicy
class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">

 <fileNamePattern>${USER_HOME}\transaction-${ENV_PREFIX}.%i.log</fileNamePattern>
         <minIndex>1</minIndex>
         <maxIndex>3</maxIndex>
      </rollingPolicy>
<triggeringPolicy
class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
        <maxFileSize>50MB</maxFileSize>
      </triggeringPolicy>
      <encoder>
         <pattern>%d [%t] %-3p -  ID:%X{UUID}  %m%n</pattern>
      </encoder>
</appender>
<appender name="ASYNC_TRAN_Logger"
class="ch.qos.logback.classic.AsyncAppender">
<appender-ref ref="transactionLoggerData" />
</appender>
<logger name="transactionLogger" level="INFO" additivity="false">
<appender-ref ref="ASYNC_TRAN_Logger" />
</logger>
<logger name="FILE" level="INFO" additivity="false">
<appender-ref ref="ASYNC_COM_FILE" />
</logger>

  <root>
    <level value="INFO"/>
    <appender-ref ref="STDOUT" />
     <appender-ref ref="FILE" />
  </root>

</configuration>

*And I am specifying the location of the configuration file before logback
is loaded:*

                        System.setProperty("logback.configurationFile",
fileName);

InputStream inputStream = new FileInputStream(fileName);

LoggerContext loggerContext = (LoggerContext) LoggerFactory
.getILoggerFactory();
loggerContext.reset();
JoranConfigurator configurator = new JoranConfigurator();

configurator.setContext(loggerContext);
configurator.doConfigure(inputStream); // loads logback file
inputStream.close();

Could you please help?

thanks,
Sara
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/logback-dev/attachments/20160824/cafbadf8/attachment.html>


More information about the logback-dev mailing list