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-…
Sent from the Users mailing list archive at Nabble.com.
Hi,
we are using the sift logger (with MDC) to separate log entries generated by user actions from log entries generated by "background" tasks. That works nicely.
However, now we want to have different log levels for these two appenders (e.g. DEBUG for "foreground.log" and WARN for "background.log"). Problem is that there is obviously only one appender. Can that be accomplished within the logback.xml?
For reference, here is our current logback.xml
<configuration scan="true" scanPeriod="30 seconds">
<appender name="SIFT" class="ch.qos.logback.classic.sift.SiftingAppender">
<discriminator class="ch.qos.logback.classic.sift.MDCBasedDiscriminator">
<key>stream</key>
<defaultValue>foreground</defaultValue>
</discriminator>
<sift>
<appender name="FILE-${stream}" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${destination}/${stream}_current.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${destination}/${stream}_%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>10MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<encoder>
<pattern>%date %-5level [%X{token}%thread] %logger{36} [%file:%line] %msg%n</pattern>
</encoder>
</appender>
</sift>
</appender>
<root level="all">
<appender-ref ref="SIFT" />
</root>
</configuration>
</nk>
---
Norbert Kiesel
Systems Architect | Engineering
MetricStream
2600 E. Bayshore Road | Palo Alto, CA - 94303
+1-650-620-2954 | nkiesel(a)metricstream.com | www.metricstream.com
Confidentiality Notice:This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited