[logback-user] logback.xml scan & reload issue when using context properties

Sagar Shah Sagar.Shah at medhost.com
Tue Dec 2 22:10:19 CET 2014


Hello Logback-User support,
I am using common logback.xml file, which is loaded programmatically from different J2EE web applications and which writes to different log files using "SiftingAppender".
Everything works fine unless logback.xml file has been modified. Once it has been modified, it gets scanned & reloaded as per configuration of scanPeriod, post which it does not recognize the context properties and it still writes all the logs, but in a separate file (with suffix of application-name_IS_UNDEFINED) for al lthe applications.
Logback version : 1.0.13

Logback configuration
<appender name="LogFile" class="ch.qos.logback.classic.sift.SiftingAppender">
     <discriminator>
           <key>application-name</key>
           <defaultValue>5</defaultValue>
     </discriminator>
     <sift>
         <appender name="${application-name}" class="ch.qos.logback.core.rolling.RollingFileAppender">
               <prudent>false</prudent>
                <file>C:/logs/${application-name}.log</file>
                <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
                           <!-- daily rollover -->
                           <fileNamePattern>c:/logs/${application-name}.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
                           <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                                <maxFileSize>5MB</maxFileSize>
                           </timeBasedFileNamingAndTriggeringPolicy>
                           <!--<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
                             <maxFileSize>5MB</maxFileSize>
                           </triggeringPolicy>-->
                           <MaxHistory>30</MaxHistory>
                     </rollingPolicy>
                     <encoder>
                           <pattern>
                                <Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n</Pattern>
                           </pattern>
                     </encoder>
            </appender>
     </sift>
</appender>



Logback Loading programmatically from the Context Listener class
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
JoranConfigurator jc = new JoranConfigurator();
jc.setContext(context);
context.reset();
context.putProperty("application-name", sce.getServletContext().getServletContextName());
String logFilePath = sce.getServletContext().getInitParameter(INIT_PARAM_NAME);
if (logFilePath==null){
throw new RuntimeException("Unable to load init parameter " + INIT_PARAM_NAME + " from web.xml file");
}
try{
jc.doConfigure(logFilePath);
} catch (Exception e){
e.printStackTrace();
     throw new RuntimeException("Unable to load logback.xml file successfully @ " + logFilePath, e);
}


Is this a known issue? Is there a fix for this already? Please advise.
Appreciate!


Regards,
Sagar Shah

Sagar Shah
Contractor
[MEDHOST logo]
6550 Carothers Pkwy STE 100 Franklin, TN 37067
p. c. f.
Sagar.Shah at medhost.com<mailto:Sagar.Shah at medhost.com>


Register for the 2015 MEDHOST MPACT Summit held September 14-18, 2015 in Nashville, Tennessee.



CONFIDENTIALITY STATEMENT: The documents accompanying this transmission may contain confidential and/or legally privileged health or other information. This information is intended only for the use of the individual or entity named above. The authorized recipient of this information is prohibited from disclosing this information to any other party unless required to do so by law or regulation and is required to destroy the information after its stated need has been fulfilled. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or action taken in reliance on the contents of these documents is strictly prohibited. If you have received this information in error, please notify the sender immediately and arrange for the return or destruction of these documents.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/logback-user/attachments/20141202/044f8ab8/attachment.html>


More information about the Logback-user mailing list