[logback-user] file appender
David Brocard
david.brocard at gmail.com
Mon Mar 17 16:36:57 CET 2008
Hi
I am new to Tomcat & logback
I'm using tomcat 5.5.25
I try to use a file appender
my conf is :
<configuration>
<appender name="STDOUT"
class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>%d{HH:mm:ss} %X{host} %-5level %logger - %msg%n</
Pattern>
</layout>
</appender>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<File>testFile.log</File>
<Append>true</Append>
<Encoding>UTF-8</Encoding>
<BufferedIO>false</BufferedIO>
<ImmediateFlush>true</ImmediateFlush>
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</
Pattern>
</layout>
</appender>
<logger name="milan">
<level value="INFO" />
</logger>
<root>
<level value="debug" />
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE" />
</root>
</configuration>
the statusprinter confirm that the configuration has been taken into
account :
|-INFO in ch.qos.logback.classic.BasicConfigurator at 6f7a6e - Setting up
default configuration.
|-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction -
Ignoring debug attribute.
|-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to
instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
|-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming
appender as [STDOUT]
|-INFO in ch.qos.logback.core.joran.action.AppenderAction - Popping
appender named [STDOUT] from the object stack
|-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to
instantiate appender of type [ch.qos.logback.core.FileAppender]
|-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming
appender as [FILE]
|-INFO in ch.qos.logback.core.joran.action.AppenderAction - Popping
appender named [FILE] from the object stack
|-INFO in ch.qos.logback.classic.joran.action.LevelAction - milan
level set to INFO
|-INFO in ch.qos.logback.classic.joran.action.LevelAction - root level
set to DEBUG
|-INFO in ch.qos.logback.core.joran.action.AppenderRefAction -
Attaching appender named [STDOUT] to Logger[root]
|-INFO in ch.qos.logback.core.joran.action.AppenderRefAction -
Attaching appender named [FILE] to Logger[root]
but no testFile.log is written
moreover, I use the code :
// logback
String chemin = getServletContext().getRealPath("/"); ;
String file = chemin + "logback.xml";
LoggerContext lc = (LoggerContext)
LoggerFactory.getILoggerFactory();
try {
JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext(lc);
lc.shutdownAndReset();
configurator.doConfigure(file);
} catch (JoranException je) {
StatusPrinter.print(lc);
} finally {
StatusPrinter.print(lc);
}
MDC.put("host", "");
logger = LoggerFactory.getLogger(this.getClass());
ch.qos.logback.classic.Logger log1 =
lc.getLogger(this.getClass());
//logger.debug (log1.getName());
System.out.println (log1.getName());
ch.qos.logback.core.Appender app1 = log1.getAppender("STDOUT");
if (app1 !=null) {
ch.qos.logback.core.Layout lay1 = app1.getLayout();
logger.debug(lay1.getContentType());
}
I can retreive the name of my logger but I cannot retrieve the
Appender object
why ?
thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://qos.ch/pipermail/logback-user/attachments/20080317/2a8159a1/attachment.htm
More information about the Logback-user
mailing list