You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Simon Dorrat <si...@gsjbw.com> on 2004/03/01 05:12:19 UTC

RE: LevelMatchFilter does not match CustomLevel

Taner,

In order to use a custom level in the LevelMatchFilter (or pretty much
anywhere), you need to specify the name of your custom class.  For example,
instead of 

	<param name="LevelToMatch" value="TRACE"/>

use

	<param name="LevelToMatch" value="TRACE#XLevel"/>

Note that the class name specified needs to be fully qualified, so add the
package info after the #.

Simon

> -----Original Message-----
> From:	Taner Akbulut [SMTP:t.akbulut@web.de]
> Sent:	Saturday, 28 February 2004 12:46 AM
> To:	log4j-user@logging.apache.org
> Subject:	LevelMatchFilter does not match CustomLevel
> 
> Hi,
> 
> i need to log my own Level in a seperate File, and the 
> another Levels FATAL,....,DEBUG in a other seperate File.
> 
> For this purpose I use the LevelMatchFilter in my log4j.xml.
> 
> But it doesnt work. I can log ERORR in a different File and DEBUG
> in a Different File with LevelMatchFilter, but if i want to log my own
> defined
> Level it logs nothing.
> 
> Can anyone help. Below i put my config und example Source.
> 
> Thanks.
> 
> 
> 
> 
> 
> ---> The Main Test Class
> public class Test{
>     Logger myLogger;
>     public Test() {
>         myLogger = Logger.getLogger(Test.class);
>     }
> 
>     public void testLog(){
>         myLogger.info("My Info Log");
>         myLogger.debug("My Debug Log");
>         myLogger.error("My Error Log");
>         myLogger.fatal("My Fatal Log");
>         
>         // should go in a seperate file, it doesnt work.
>         myLogger.log(XLevel.TRACE,"Trace Log");
>     }
> 
>     public static void main(String argv[]){
>         Test my = new Test();
>         my.testLog();
>     }
> }
> 
> -----> The Custom Level
> // For test purposes i had take the exaple Custom Level from
> // the log4J sources. Anyway it doesnt work.
> public final class XLevel extends Level {
>     static public final int TRACE_INT = Level.FATAL_INT + 1;
>     private static String TRACE_STR = "TRACE";
>     public static final XLevel TRACE = new XLevel(TRACE_INT,TRACE_STR, 7);
> 
>     protected XLevel(int level, String strLevel, int syslogEquiv) {
>         super(level, strLevel, syslogEquiv);
>     }
> 
>     public static Level toLevel(String sArg) {
>         return (Level) toLevel(sArg, XLevel.TRACE);
>     }
> 
>     public static Level toLevel(String sArg, Level defaultValue) {
>         if ( sArg == null ) {
>             return defaultValue;
>         }
>         String stringVal = sArg.toUpperCase();
>         if ( stringVal.equals(TRACE_STR) ) {
>             return XLevel.TRACE;
>         }
>         return Level.toLevel(sArg, (Level) defaultValue);
>     }
> 
>     public static Level toLevel(int i)
>             throws IllegalArgumentException {
>         if ( i == TRACE_INT ) {
>             return XLevel.TRACE;
>         } else {
>             return Level.toLevel(i);
>         }
>     }
> }
> 
> 
> ------> log4j.xml
> <log4j:configuration>
>    <appender name="infoLogsFile" class="org.apache.log4j.FileAppender">
>       <param name="file" value="trace_messages.log"/>
>       <layout class="org.apache.log4j.PatternLayout">
>         <param name="ConversionPattern" value="%d{MM-dd-yyyy HH:mm:ss}
> %-5p %c - %m%n"/>
>       </layout>
>       <filter class="org.apache.log4j.varia.LevelMatchFilter">
>         <param name="LevelToMatch" value="TRACE"/>
>         <param name="AcceptOnMatch" value="true"/>
>       </filter>
>       <filter class="org.apache.log4j.varia.DenyAllFilter"/>
>   </appender>
> 
>   <appender name="otherLogsFile" class="org.apache.log4j.FileAppender">
>       <param name="file" value="debug_messages.log"/>
>       <layout class="org.apache.log4j.PatternLayout">
>         <param name="ConversionPattern" value="%d{MM-dd-yyyy HH:mm:ss}
> %-5p %c - %m%n"/>
>       </layout>
>       <filter class="org.apache.log4j.varia.LevelMatchFilter">
>                         <param name="LevelToMatch" value="DEBUG"/>
>                         <param name="AcceptOnMatch" value="true"/>
>       </filter>
>       <!-- <filter class="org.apache.log4j.varia.LevelRangeFilter">
>                         <param name="LevelMin" value="DEBUG"/>
>                         <param name="LevelMax" value="FATAL"/>
>                         <param name="AcceptOnMatch" value="true"/>
>       </filter> -->
>       <filter class="org.apache.log4j.varia.DenyAllFilter"/>
>   </appender>
> 
>   <root>
>                 <priority value="ALL"/>
>                 <appender-ref ref="otherLogsFile"/>
>                 <appender-ref ref="infoLogsFile"/>
>   </root>
> </log4j:configuration>
> 
> __________________________________________________________________________
> ____
> Nachrichten, Musik und Spiele schnell und einfach per Quickstart im 
> WEB.DE Screensaver - Gratis downloaden:
> http://screensaver.web.de/?mc=021110
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org


Goldman Sachs JBWere
Disclosure of Interest
ORG:  Goldman Sachs JBWere and/or its affiliates expect to receive or intend to seek compensation for financial and advisory services in the next 3 months from the company or its affiliates.



GOLDMAN SACHS JBWERE PTY LTD DISCLAIMER

Goldman Sachs JBWere Pty Ltd and its related entities distributing this document and each of their respective directors, officers and agents ("the Goldman Sachs JBWere Group") believe that the information contained in this document is correct and that any estimates, opinions, conclusions or recommendations contained in this document are reasonably held or made as at the time of compilation.  However, no warranty is made as to the accuracy or reliability of any estimates, opinions, conclusions, recommendations (which may change without notice) or other information contained in this document and, to the maximum extent permitted by law, the Goldman Sachs JBWere Group disclaims all liability and responsibility for any direct or indirect loss or damage which may be suffered by any recipient through relying on anything contained or omitted from this document.

Goldman Sachs JBWere does not represent or warrant the attached files are free from computer viruses or other defects.  The attached files are provided, and may only be used, on the basis that the user assumes all responsibility for any loss, damage or consequence resulting directly or indirectly from use.



Goldman Sachs JBWere
Disclosure of Interest
ALL:  Goldman Sachs JBWere and/or its affiliates expect to receive or intend to seek compensation for financial  and advisory services in the next 3 months from the company or its affiliates.


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