[logback-user] MDC and env-entry
José Juan Montiel
josejuan.montiel at eurobits.es
Fri Feb 4 09:10:29 CET 2011
Hi, again with another question.
With aspectj, in injecting a var in MCD, something like this...
MDC.put("code",var);
in some places, depending something, and i'm using this to generate a
diferent file for this something like
<appender name="APPENDER"
class="ch.qos.logback.classic.sift.SiftingAppender">
<filter class="ch.qos.logback.core.filter.EvaluatorFilter">
<evaluator
class="ch.qos.logback.classic.boolex.JaninoEventEvaluator">
<expression>
(marker != null)
&& (
(marker.contains("ASPECTJ")) ||
(marker.contains("SOAP")))
</expression>
</evaluator>
<onMatch>DENY</onMatch>
</filter>
<discriminator>
<Key>code</Key>
<DefaultValue>0000</DefaultValue>
</discriminator>
<sift>
<appender name="FILE-${code}"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<prudent>${prudent}</prudent>
<!-- 5 líneas de stacktrace para las excepciones -->
<encoder
class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>%date - [%thread] - %.-20M - %L -
cn=%contextName - [%thread] - [%X{code}] - %message%n
%exception{5}</Pattern>
</encoder>
<rollingPolicy
class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>${USER_HOME}/${backupDir}${code}.%d${patronRolling}</FileNamePattern>
<MaxHistory>${maxHistory}</MaxHistory>
</rollingPolicy>
</appender>
</sift>
</appender>
ASPECTJ and SOAP are Markers of other traces, that i don't want to see here.
This way i get
in my root log directory ${USER_HOME}/${backupDir} files like
0001.log
0002.log
But, now i have multile apps (wars and ejbs) where i use
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="
http://java.sun.com/xml/ns/javaee" xmlns:web="
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID"
version="2.5">
...
<env-entry>
<description>JNDI logging context for this app</description>
<env-entry-name>logback/context-name</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>APP1</env-entry-value>
</env-entry>
<env-entry>
<description>URL for configuring logback context</description>
<env-entry-name>logback/configuration-resource</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>logback.xml</env-entry-value>
</env-entry>
...
</web-app>
ejb-jar.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise
JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
<ejb-jar>
<enterprise-beans>
<session>
...
<env-entry>
<description>JNDI logging context for this app</description>
<env-entry-name>logback/context-name</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>EJB1</env-entry-value>
</env-entry>
<env-entry>
<description>URL for configuring logback
context</description>
<env-entry-name>logback/configuration-resource</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>logback.xml</env-entry-value>
</env-entry>
...
</session>
</enterprise-beans>
...
</ejb-jar>
a env-entry to identificate. I know that insede file, i use cn=%contextName
to see this context but...
How could i use this context like i use ${code} to separete this files
(0001.log, 0002.log) in diferents directories.
Thanks.
--
Jose Juan Montiel Martinez
Eurobits Technologies
Calle Musgo 3, 1ª Planta
28023 Madrid
T +34-917080300
F +34-913077480
josejuan.montiel at eurobits.es
http://www.eurobits.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://qos.ch/pipermail/logback-user/attachments/20110204/658948b0/attachment-0001.html>
More information about the Logback-user
mailing list