[logback-user] Log file is created successfully but no logging

bayrak mr.i.bayraktar at gmail.com
Wed Feb 5 09:45:34 CET 2014


With the below configuration settings in my JSF project, I am able to get the
logging file but no logging ends at the log file created. See the details: 

I have the below common configuration for my all JSF project each of which
includes its own sl4j and logback libraries. My JSF projects are running on
jetty. 

<configuration scan="true" scanPeriod="30 seconds">
        <property name="loggingHome" value="C://server//default//logs" />
        <appender name="FILE"
class="ch.qos.logback.core.rolling.RollingFileAppender">
                <file>${loggingHome}/${application-name}_log.xml</file>
                <rollingPolicy
class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
                        
                       
<fileNamePattern>${loggingHome}/${application-name}_log.%d{yyyy-MM-dd}.xml%i.gz</fileNamePattern>
                        <timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                                
                                <maxFileSize>50MB</maxFileSize>
                        </timeBasedFileNamingAndTriggeringPolicy>
                        <maxHistory>30</maxHistory>
                </rollingPolicy>
                <encoder>
                        <pattern>%date %-5level %logger -
%msg%n%ex{full}</pattern>
                </encoder>
        </appender>
        <root level="DEBUG">
                <appender-ref ref="FILE" />
        </root>
</configuration>

I have defined a ServletContextListener and in contextInitialized I have the
following piece of code: 


import javax.servlet.ServletContextEvent; 
import javax.servlet.ServletContextListener; 

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

import ch.qos.logback.classic.LoggerContext; 
import ch.qos.logback.classic.joran.JoranConfigurator; 
import ch.qos.logback.core.joran.spi.JoranException; 
import ch.qos.logback.core.util.StatusPrinter; 

public class LogbackContextInitializer implements ServletContextListener { 
        /* 
         * (non-Javadoc) 
         * 
         * @see
javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent) 
         */ 
        @Override 
        public void contextDestroyed(ServletContextEvent sce) { 

                
        } 

        /* 
         * (non-Javadoc) 
         * 
         * @see
javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent) 
         */ 
        @Override 
        public void contextInitialized(ServletContextEvent sce) { 

                LoggerContext context = (LoggerContext)
LoggerFactory.getILoggerFactory(); 
                try { 
                        JoranConfigurator jc = new JoranConfigurator(); 
                        jc.setContext(context); 
                        context.reset(); // override default configuration 
                        // inject the name of the current application as
"application-name" 
                        // property of the LoggerContext 
                        context.putProperty("application-name", "myapp"); 
                       
jc.doConfigure("C://server//default//config//logback.xml"); 

                        StatusPrinter.print(context); 
                       
StatusPrinter.printInCaseOfErrorsOrWarnings(context); 

                        Logger log =
context.getLogger(LogbackContextInitializer.class); 
                        log.error("Hi I am there"); 
                        
                        log.debug("Hi I am there"); 

                } catch (JoranException e) { 
                        sce.getServletContext().log("Error configuring
logback!", e); 
                } 

        } 

} 


When application starts, log file is created as I wanted. So, the property
application-name is set correctly but no logging is done with Status print
or log error. 

Any idea what I am missing over here.



--
View this message in context: http://logback.10977.n7.nabble.com/Log-file-is-created-successfully-but-no-logging-tp13233.html
Sent from the Users mailing list archive at Nabble.com.


More information about the Logback-user mailing list