<div class="gmail_quote">On Wed, Jun 20, 2012 at 1:34 PM, George, Kenneth V [NTK] <span dir="ltr"><<a href="mailto:Kenneth.V.George@sprint.com" target="_blank">Kenneth.V.George@sprint.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div lang="EN-US" link="blue" vlink="purple">
<div>
<p class="MsoNormal">Good afternoon.</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">I have a situation where I need to log information to 2 separate files, but under different conditions, for the same context/class files.</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">Basically, I have 2 files: 1 log, 1 alarm_log.</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">I need to set the level for reporting to INFO, but only log WARN/ERROR messages to alarm_log when a MDC value of “SEND_ALARM” is set. I have tried to place a <filter> of type “ch.qos.logback.core.filter.EvaluatorFilter” and cannot seem
to get it to work, messages of Level INFO show-up in the alarm_log.</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">Can this even be done (maybe I am just using it wrong)? Here is the section of my logback.xml file specifying the appender:</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal"><span style="font-family:"Courier New""> <appender name="ALARM" class="ch.qos.logback.core.rolling.RollingFileAppender"></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> <filter class="ch.qos.logback.core.filter.EvaluatorFilter"></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> <evaluator></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> <expression></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> if (mdc == null || mdc.get("SEND_ALARM") == null)</span></p></div></div></blockquote><div><br></div><div>No need to check for (mdc == null) because it's guaranteed to not be null in versions 0.9.30 and later.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div lang="EN-US" link="blue" vlink="purple"><div>
<p class="MsoNormal"><span style="font-family:"Courier New""> return false;</span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">
</span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> return true;</span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> </expression></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> </evaluator></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> </filter></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> <file>logs/alarms.log</file></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> <!-- daily rollover -->
</span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> <fileNamePattern>logs/archive/logFile.%d{yyyy-MM-dd}.log</fileNamePattern></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> </span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> <!-- keep 30 days' worth of history -->
</span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> <maxHistory>30</maxHistory></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> </rollingPolicy></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> </span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> <encoder></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> <pattern>%date{MMM dd, yyyy hh:mm:ss} %-5level %msg%n</pattern></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> </encoder></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> </appender></span></p>
<p class="MsoNormal"> </p></div></div></blockquote><div><br></div><div>Try this:</div><div><br></div><div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span><appender name="ALARM" class="ch.qos.logback.core.rolling.RollingFileAppender"></font></div>
<div><font face="courier new, monospace"> <font color="#3366ff"><filter class="ch.qos.logback.core.filter.JaninoEvaluatorFilter"> </font></font></div><div><font face="courier new, monospace" color="#3366ff"> <evaluator></font></div>
<div><font face="courier new, monospace" color="#3366ff"> <expression>return (mdc.get("SEND_ALARM") != null) && (level > INFO);</expression></font></div><div><font face="courier new, monospace" color="#3366ff"> </evaluator></font></div>
<div><font face="courier new, monospace" color="#3366ff"> <OnMismatch>DENY</OnMismatch></font></div><div><font face="courier new, monospace" color="#3366ff"> <OnMatch>ACCEPT</OnMatch></font></div>
<div><font face="courier new, monospace" color="#3366ff"> </filter></font></div><div><font face="courier new, monospace"> <file>logs/alarms.log</file></font></div><div><font face="courier new, monospace"> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"></font></div>
<div><font face="courier new, monospace"> <!-- daily rollover --></font></div><div><font face="courier new, monospace"> <fileNamePattern>logs/archive/logFile.%d{yyyy-MM-dd}.log</fileNamePattern></font></div>
<div><font face="courier new, monospace"> </font></div><div><font face="courier new, monospace"> <!-- keep 30 days' worth of history --></font></div><div><font face="courier new, monospace"> <maxHistory>30</maxHistory></font></div>
<div><font face="courier new, monospace"> </rollingPolicy></font></div><div><font face="courier new, monospace"> </font></div><div><font face="courier new, monospace"> <encoder></font></div><div>
<font face="courier new, monospace"> <pattern>%date{MMM dd, yyyy hh:mm:ss} %-5level %msg%n</pattern></font></div><div><font face="courier new, monospace"> </encoder></font></div><div><font face="courier new, monospace"> </appender></font></div>
</div><div> </div></div>