2

I'm using log4back in a really large progect (lots of class). In the main class i configure the logger ot get the configuration froma an xml file:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>    
<appender name="SIFT" class="ch.qos.logback.classic.sift.SiftingAppender">
       <discriminator>
        <key>filePath</key>
        <defaultValue>C:/</defaultValue>
    </discriminator>

    <sift>  
        <appender name="startupDailyRolloverAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
            <file>${filePath}/application.log</file>
            <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
                <fileNamePattern>${filePath}/application.log.%d{yyyyMMdd}_%d{HHmmss,aux}</fileNamePattern>
                <maxHistory>5</maxHistory>                
            </rollingPolicy>
            <encoder>
                <pattern>%d{dd/MM/yyyy_HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n</pattern>
            </encoder>
        </appender>
    </sift>        
</appender>

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">      
    <encoder>
        <pattern>%d{dd/MM/yyyy_HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n</pattern>
    </encoder>
</appender>

<root level="info">
    <appender-ref ref="SIFT" />
</root>

<root level="info">
    <appender-ref ref="STDOUT" />
</root>-->

This is the part where i configure the logger:

LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
    try {
        JoranConfigurator configurator = new JoranConfigurator();
        configurator.setContext(context);
        context.reset();
        URL res = Ned.class.getResource("package/resources/logback.xml");
        if (res != null) {                   
            configurator.doConfigure(res);
        }
        MDC.put("filePath", Main.applicationDir.substring(0, Main.applicationDir.length() - 1));
    } catch (JoranException je) {
    je.printStackTrace();
    }
StatusPrinter.printInCaseOfErrorsOrWarnings(context);

Now, in each class, i define the logger as a static variable like this

 private static final Logger logger = LoggerFactory.getLogger(NomeClasse.class);

This is quite perfect, since i ca log many of the class output into the file i specified. Unfortunately sometimes some class don't log any kind of out put, for example with this line of code

logger.error("Unexpected failure: " + ret.getStatus());

or even his

logger.error(ex.getMessage(), ex);

have no output into the file i specified. And in each class i define the logger as static variable as stated above. Can i have some hint to figure out what's wrong?

I Used this as reference but i cannot solve the issue.

Community
  • 1
  • 1
Razlo3p
  • 455
  • 2
  • 7
  • 28

0 Answers0