20030905 Friday September 05, 2003

Log4J: 2 Appenders - one gets errors, other gets all (doesn't work) I sent a message to the log4j-user mailing list this afternoon, but have not received a response - so hopefully someone can help me out. Here's the problem I'm having:

I have two appenders - a console and a file.  I want all messages to 
go to the console and only <= error to go to the file.

In my file appender, I have a filter to only get the error messages:

<filter class="org.apache.log4j.varia.LevelRangeFilter">
  <param name="LevelMax" value="ERROR" />
</filter>

Then in <root> I have:

  <root>
    <level value="DEBUG"/>
    <appender-ref ref="CONSOLE"/>
    <appender-ref ref="FILE"/>
  </root>

From the documentation I've read (i.e. http://tinyurl.com/meef), this
*should* work.  However, all messages get logged to both the console
appender and the file appender.

Any advice is appreciated. Posted in Java at Sep 05 2003, 10:11:38 PM MDT 6 Comments

Comments:

Forget the filter. just add a threshold to your appender. <param name="Threshold" value="error" /> If you wanted JUST error it wouldn't work, because fatal gets selected to. For that you would need a filter.

Posted by Yuri on September 06, 2003 at 10:25 PM MDT #

I want fatal and error - that's why I'm using a filter.

Posted by Matt Raible on September 07, 2003 at 10:38 AM MDT #

mh, if you want log >= error go to the file (is it correct? Do you want error and fatal, right?) threshold="ERROR" is the corect setting. Threshold select the minimum severity to be logged, you need a filter only if you need to include specific severities (not >= x). Your current setting, filter LevelMax=ERROR, includes everything from debug to error (fatal is > error, remember)

Posted by Fabrizio Giustina on September 08, 2003 at 02:21 AM MDT #

Matt, I don't know this filter stuff in log4j (yet), but my gutt feeling tells me you should set LevelMin to ERROR instead of LevelMax. Does this make sense? It seems to be done that way in the email you're referring to too...

Posted by Tom Klaasen on September 08, 2003 at 03:05 AM MDT #

Tom - you were correct - my conception of Min and Max in Log4j was back-asswards. Thanks - your suggestion worked.

Posted by Matt Raible on September 08, 2003 at 12:56 PM MDT #

Its still a bit strange to use a filter when the Appenders already support this. But hey, whatever floats your boat.

Posted by Unknown on September 09, 2003 at 07:37 AM MDT #

Post a Comment:
  • HTML Syntax: Allowed
Click me to subscribe
Matt Raible is a Web Architect who enjoys developing applications with open source technologies. Contact me for rates.
« January 2009
SunMonTueWedThuFriSat
    
1
2
3
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
       
Today

Recent Entries

Tag Cloud