Here's the relevant Log4j debug output (no error thrown upon parsing, as you can see)...

log4j: Class name: [org.apache.log4j.rolling.RollingFileAppender]
log4j: Setting property [fileNamePattern] to [./logs/myapp.%d.log.gz].
log4j: Parsing layout of class: "org.apache.log4j.PatternLayout"
log4j: Setting property [conversionPattern] to [%d{ABSOLUTE} [%-5p][%-8.8t]: %39.39c - %m%n].
log4j: Setting property [expression] to [(level >= info)].
log4j: Adding filter of type [class org.apache.log4j.filter.ExpressionFilter] to appender named [default].
log4j: setFile called: ./logs/myapp.2012-10-05.log, true
log4j: setFile ended
log4j: Adding appender named [default] to category [root].


Yet, I get TRACE and DEBUG output in the log file.  I even tried a second run, removing the parens and had just "level >= info".  Same thing.  I still get TRACE and DEBUG output when I've clearly specified in the expression that it should filter everything but INFO and above.


Jake

On Fri, 5 Oct 2012 13:47:27 -0700
 Scott Deboy <scott.de...@gmail.com> wrote:
Right, in the XML it has to be escaped for the filter.  Chainsaw uses the
same expression-handling code the ExpressionFilter uses (ExpressionRule),
which is why as long as the xml parsing is working as expected it should be
an equivalent test.  ExpressionRule throws an exception if the expression
couldn't be parsed, so if you turned on -Dlog4j.debug you'd see an error
when the ExpressionFilter parsing happens.

Scott

On Fri, Oct 5, 2012 at 1:38 PM, Jacob Kjome <h...@visi.com> wrote:

When you added the URL to the "marker" field, did you add it with "&" or
"&amp;"?

When setting it via MDC, I'd be setting it as "&".  But, in XML, it must
be escaped using "&amp;" otherwise we'll get a parsing error, since "&" is
a reserved character that defines the start of an entity reference.

In fact, I'm not sure how you were able to define "level == info &&
prop.marker=..." without experiencing a parsing error, such as....

log4j:WARN Fatal parsing error 15 and column 67
log4j:WARN The entity name must immediately follow the '&' in the entity
reference.
log4j:ERROR Could not parse url [file:./log4j.xml].
org.xml.sax.SAXParseException: The entity name must immediately follow the
'&' in the entity reference.
         at com.sun.org.apache.xerces.**internal.parsers.DOMParser.**
parse(DOMParser.java:249)
         at com.sun.org.apache.xerces.**internal.jaxp.**
DocumentBuilderImpl.parse(**DocumentBuilderImpl.java:284)
         at org.apache.log4j.xml.**DOMConfigurator$2.parse(**
DOMConfigurator.java:769)
         at org.apache.log4j.xml.**DOMConfigurator.doConfigure(**
DOMConfigurator.java:871)


In any case, if anything, I'd expect to see **no** TRACE output if it had
trouble matching the value.  Instead, I see **all** trace output.  It's as
if it were able to parse the "LEVEL == TRACE" part, but then silently
ignore the rest of the configuration that, maybe, it was unable to parse?
Or maybe, it silently ignored the entire expression altogether, leaving me
with only the fact that the TRACE level is enabled for the particular
logger I am using, so the TRACE info was logged regardless.

In fact, the latter appears to be the case.  The expression is totally
ignored.  I tried the following minimal expression, and I continued to get
DEBUG info, as well as TRACE info...


     <appender name="default" class="org.apache.log4j.**
rolling.RollingFileAppender">
         ...
         <filter class="org.apache.log4j.**filter.ExpressionFilter">
             <param name="Expression"
                    value="(level >= info)"/>
         </filter>
     </appender>

Are you sure this thing works outside of Chainsaw?  I'm not using Chainsaw
here, just logging to a RollingFileAppender in a command-line application.
BTW, I'm also using SLF4J, binding to Log4j-1.2.17.


Jake


On Thu, 4 Oct 2012 15:38:59 -0700
  Scott Deboy <scott.de...@gmail.com> wrote:

Hey Jake

I tried this in the latest developer snapshot of Chainsaw..I pulled up a
log in Chainsaw which contained info and debug entries (I didn't have a
log
with trace).

And I added your URL value you provided in the 'marker' field of two of my
INFO entries

This expression:

(level <= debug) || (level == info && prop.marker == '
https://somedomain/somepath/**somepage.do?someparam=someval&**
amp;anotherparam=anotherval<https://somedomain/somepath/somepage.do?someparam=someval&anotherparam=anotherval>
')

Gave me all of the debug entries and two info level entries..

It could be something weird with trace...or something weird with parsing
the &amp; ??? but...this should work..

Scott


On Wed, Oct 3, 2012 at 8:56 AM, Jacob Kjome <h...@visi.com> wrote:


Thanks Scott,

However, while I didn't experience an error in parsing the expression
this
time, the expression seems to be, at least partially, ignored.

Below is the relevant config, where com.mypackage.MyClass sets MDC (via
SLF4J) with a "url" key and the currently processed URL as the value,
then
logs the page content for the URL at the TRACE level (with MDC removal of
"url" immediately after logging the page content).  But rather than
getting
TRACE output for only the URL defined in the Expression, I get **all**
TRACE output.  It's like it sees the "LEVEL == TRACE" but then ignores
the
"&&".  Thoughts?


      <appender name="default" class="org.apache.log4j.**
rolling.RollingFileAppender">

          ...

          <filter class="org.apache.log4j.****filter.ExpressionFilter">
              <param name="Expression"
                     value="( LEVEL >= DEBUG ) || ( LEVEL == TRACE
&amp;&amp; PROP.url == 'https://somedomain/somepath/****<https://somedomain/somepath/**>
somepage.do?someparam=someval&****amp;anotherparam=anotherval<**
https://somedomain/somepath/**somepage.do?someparam=someval&**
anotherparam=anotherval<https://somedomain/somepath/somepage.do?someparam=someval&anotherparam=anotherval>
>'

)"/>
          </filter>
      </appender>

      <logger name="com.mypackage.MyClass">
          <level value="TRACE"/>
      </logger>

      <root>
          <level value="WARN"/>
          <appender-ref ref="default"/>
      </root>



On Tue, 2 Oct 2012 15:53:57 -0700
   Scott Deboy <scott.de...@gmail.com> wrote:

  Try PROP.url == 'blah'

MDC entries are really just set as properties of the log4j events.

Scott

On Tue, Oct 2, 2012 at 1:10 PM, Jacob Kjome <h...@visi.com> wrote:


  I'm trying to use the ExpressionFilter [1] from Log4j Extras to limit
logging for a particular appender to those cases where MDC contains a
"url"
entry that equals some specific value.  But I get an error from Log4j
saying "Invalid EQUALS rule - MDC.url is not a supported field" (see
below
for complete error output from Log4j).  I'm using the latest versions
of
Log4j-1.x and Log4j-extras.  Here's the relevant config...

<appender...>
       ....
       <filter class="org.apache.log4j.******filter.ExpressionFilter">


           <param name="Expression" value="MDC.url == '
http://somedomain/somepath'"/******>


       </filter>
</appender>

Based on the documentation [2] and commit comment [3] I found, it seems
like this should work.  What am I missing?


Here's the complete error output from Log4j...

log4j:ERROR Could not create an Appender. Reported error follows.
java.lang.******IllegalArgumentException: Invalid EQUALS rule -
MDC.url is
not a supported field
           at org.apache.log4j.rule.******
EqualsRule.<init>(EqualsRule.*****
*java:62)
           at org.apache.log4j.rule.******
EqualsRule.getRule(EqualsRule.******
java:100)
           at org.apache.log4j.rule.******
EqualsRule.getRule(EqualsRule.******
java:85)
           at org.apache.log4j.rule.******RuleFactory.getRule(**
RuleFactory.java:154)
           at org.apache.log4j.rule.******ExpressionRule$**
PostFixExpressionCompiler.******compileExpression(****
ExpressionRule.java:149)
           at org.apache.log4j.rule.******ExpressionRule.getRule(**
ExpressionRule.java:100)
           at org.apache.log4j.filter.******ExpressionFilter.****
activateOptions(**
ExpressionFilter.java:95)
           at org.apache.log4j.config.******PropertySetter.activate(**
PropertySetter.java:307)
           at org.apache.log4j.xml.******DOMConfigurator.parseFilters(*
*****
DOMConfigurator.java:380)
           at org.apache.log4j.xml.******DOMConfigurator.parseAppender(
******
DOMConfigurator.java:273)
           at org.apache.log4j.xml.******DOMConfigurator.****
findAppenderByName(**
DOMConfigurator.java:176)
           at org.apache.log4j.xml.******DOMConfigurator.**
findAppenderByReference(******DOMConfigurator.java:191)
           at org.apache.log4j.xml.******DOMConfigurator.**
parseChildrenOfLoggerElement(******DOMConfigurator.java:523)
           at org.apache.log4j.xml.******DOMConfigurator.parseRoot(**
DOMConfigurator.java:492)
           at org.apache.log4j.xml.******DOMConfigurator.parse(**
DOMConfigurator.java:1006)
           at org.apache.log4j.xml.******DOMConfigurator.doConfigure(**
DOMConfigurator.java:872)
           at org.apache.log4j.xml.******DOMConfigurator.doConfigure(**
DOMConfigurator.java:778)
           at org.apache.log4j.helpers.******OptionConverter.**
selectAndConfigure(******OptionConverter.java:526)
           at org.apache.log4j.LogManager.<*****
*clinit>(LogManager.java:127)
           at org.slf4j.impl.******Log4jLoggerFactory.getLogger(******
Log4jLoggerFactory.java:64)
           at org.slf4j.LoggerFactory.******
getLogger(LoggerFactory.java:*****
*270)
           at org.slf4j.LoggerFactory.******
getLogger(LoggerFactory.java:*****
*281)


[1] http://logging.apache.org/******log4j/companions/extras/**<http://logging.apache.org/****log4j/companions/extras/**>
<htt**p://logging.apache.org/****log4j/companions/extras/**<http://logging.apache.org/**log4j/companions/extras/**>
>
apidocs/org/apache/log4j/******filter/ExpressionFilter.html<**h**

ttp://logging.apache.org/****log4j/companions/extras/**<http://logging.apache.org/**log4j/companions/extras/**>
apidocs/org/apache/log4j/****filter/ExpressionFilter.html<h**
ttp://logging.apache.org/**log4j/companions/extras/**
apidocs/org/apache/log4j/**filter/ExpressionFilter.html<http://logging.apache.org/log4j/companions/extras/apidocs/org/apache/log4j/filter/ExpressionFilter.html>
>
>
[2] https://logging.apache.org/******log4j/companions/extras/**<https://logging.apache.org/****log4j/companions/extras/**>
<ht**tps://logging.apache.org/****log4j/companions/extras/**<https://logging.apache.org/**log4j/companions/extras/**>
>
apidocs/org/apache/log4j/spi/******LoggingEventFieldResolver.****html<
https://logging.apache.**org/**log4j/companions/extras/**
apidocs/org/apache/log4j/spi/****LoggingEventFieldResolver.**html<
https://logging.apache.**org/log4j/companions/extras/**
apidocs/org/apache/log4j/spi/**LoggingEventFieldResolver.html<https://logging.apache.org/log4j/companions/extras/apidocs/org/apache/log4j/spi/LoggingEventFieldResolver.html>
**>
**>
[3] http://mail-archives.apache.******org/mod_mbox/logging-log4j-****
dev/200310.mbox/%******3C20031027083531.85866.qmail@******
minotaur.apache.org%3E<http:/****/mail-archives.apache.org/**mod_**<http://mail-archives.apache.org/mod_**>
mbox/logging-log4j-dev/200310.****mbox/%3C20031027083531.**85866.**
qm...@minotaur.apache.org%3E<h**ttp://mail-archives.apache.**
org/mod_mbox/logging-log4j-**dev/200310.mbox/%**
3C20031027083531.85866.qmail@**minotaur.apache.org%3E<http://mail-archives.apache.org/mod_mbox/logging-log4j-dev/200310.mbox/%3c20031027083531.85866.qm...@minotaur.apache.org%3E>
>
>



Jake

------------------------------******--------------------------**--**
--**---------
To unsubscribe, e-mail: log4j-user-unsubscribe@****loggi**
ng.apache.org<http://**logging.apache.org <http://logging.apache.org>>
<log4j-user-**unsubscribe@**logging.apache.org<unsubscr...@logging.apache.org>
<log4j-user-**unsubscr...@logging.apache.org<log4j-user-unsubscr...@logging.apache.org>
**>
**>
For additional commands, e-mail: log4j-user-help@logging.****apac**
he.org<http://apache.org**>
<log4j-user-help@**logging.**apache.org <http://logging.apache.org><
log4j-user-help@**logging.apache.org<log4j-user-h...@logging.apache.org>
>
>




------------------------------****----------------------------**
--**---------
To unsubscribe, e-mail: log4j-user-unsubscribe@**loggi**ng.apache.org<http://logging.apache.org>
<log4j-user-**unsubscr...@logging.apache.org<log4j-user-unsubscr...@logging.apache.org>
**>
For additional commands, e-mail: log4j-user-help@logging.**apac**he.org<http://apache.org>
<log4j-user-help@**logging.apache.org<log4j-user-h...@logging.apache.org>
>




------------------------------**------------------------------**---------
To unsubscribe, e-mail: log4j-user-unsubscribe@**logging.apache.org<log4j-user-unsubscr...@logging.apache.org> For additional commands, e-mail: log4j-user-help@logging.**apache.org<log4j-user-h...@logging.apache.org>




---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-user-h...@logging.apache.org

Reply via email to