Included below are my properties file ( properties.LogTest2.xml ),
my test driver ( LogTest2.java ) and the resultant output ( out ).
Basically, what I've done is subclassed Category, CategoryFactory and Priority.
I created a Priority called NOTIFY because I want to selectively write only
log events of that priority to a different log file. In my xml, I have an appender
called NOTIFY_TO_LOG which *attempts* to write all NOTIFY events
out to a file log_notification_out.txt.
As you can see from the output ( "out" below ), it appears that everything
runs as it should. However, the file log_notification_out.txt *does* get
created. However, it does NOT contain any data.
When I change the PRIORITY_TO_MATCH value in the xml file
from NOTIFY#com.ebss.utilities.PPCSPriority to INFO, the
log_notification_out.txt file *is* successfully written.
Does this imply that my subclasses are wrong ?
(thanks)
///////////////////////// properties.LogTest2.xml
//////////////////////////////////////////////////////
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd" [
<!ENTITY PPCSCategory "com.ebss.utilities.PPCSCategory">
]>
<log4j:configuration debug="true">
<!-- Indicate what factory is being used by PPCSCategory -->
<categoryFactory name="PPCSCategory"
class="com.ebss.utilities.PPCSCategoryFactory">
</categoryFactory>
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ISO8601} <%p> [%c{2}] :
%m%n"/>
</layout>
</appender>
<!-- Define the NOTIFY_TO_LOG appender -->
<appender name="NOTIFY_TO_LOG" class="org.apache.log4j.FileAppender">
<param name="File" value="log_notification_out.txt"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ISO8601} PPCS: %m%n"/>
</layout>
<!-- Only write events with Priority=NOTIFY to this appender -->
<filter class="org.apache.log4j.varia.PriorityMatchFilter">
<param name="PriorityToMatch"
value="NOTIFY#com.ebss.utilities.PPCSPriority" />
<param name="AcceptOnMatch" value="true" />
</filter>
<filter class="org.apache.log4j.varia.DenyAllFilter">
</filter>
</appender>
<root>
<priority value="DEBUG"/>
<appender-ref ref="CONSOLE"/>
<appender-ref ref="NOTIFY_TO_LOG"/>
</root>
</log4j:configuration>
///////////////////////// LogTest2.java
//////////////////////////////////////////////////////
import org.apache.log4j.xml.DOMConfigurator;
import com.ebss.utilities.PPCSCategory ;
public class LogTest2
{
public static void main( String[] args )
{
DOMConfigurator.configure( "properties.LogTest2.xml" ) ;
LogTest2 lt2 = new LogTest2() ;
lt2.go() ;
}
public void go()
{
PPCSCategory cat = ( PPCSCategory)
PPCSCategory.getInstance( LogTest2.class.getName() ) ;
cat.debug(" DEBUG is ok") ;
cat.info(" INFO is ok") ;
cat.warn(" WARN is ok") ;
cat.notify(" NOTIFY is ok.") ;
org.apache.log4j.Category.shutdown() ;
}
}
///////////////////////// out //////////////////////////////////////////////////////
log4j: Disable override="null".
log4j: Disable ="null".
log4j: Priority value for root is [DEBUG].
log4j: root priority set to DEBUG
log4j: Class name: [org.apache.log4j.ConsoleAppender]
log4j: Parsing layout of class: "org.apache.log4j.PatternLayout"
log4j: Setting property [conversionPattern] to [%d{ISO8601} <%p> [%c{2}] : %m%n].
log4j: Adding appender named [CONSOLE] to category [root].
log4j: Class name: [org.apache.log4j.FileAppender]
log4j: Setting property [file] to [log_notification_out.txt].
log4j: Parsing layout of class: "org.apache.log4j.PatternLayout"
log4j: Setting property [conversionPattern] to [%d{ISO8601} PPCS: %m%n].
log4j: Setting property [priorityToMatch] to [NOTIFY#com.ebss.utilities.PPCSPriority].
log4j: Setting property [acceptOnMatch] to [true].
log4j: Adding appender named [NOTIFY_TO_LOG] to category [root].
2001-06-27 11:14:35,666 <DEBUG> [LogTest2] : DEBUG is ok
2001-06-27 11:14:35,666 <INFO> [LogTest2] : INFO is ok
2001-06-27 11:14:35,666 <WARN> [LogTest2] : WARN is ok
2001-06-27 11:14:35,666 <NOTIFY> [LogTest2] : PPCS-NOTIFY> NOTIFY is ok.
///////////////////////////////////////////////////////////////////////////////
----- Original Message -----
From: "Ceki Gülcü" <[EMAIL PROTECTED]>
To: "LOG4J Users Mailing List" <[EMAIL PROTECTED]>
Sent: Tuesday, June 26, 2001 10:29 PM
Subject: Re: Problems with Filtering Extended Categories and Priorities
Jay,
I don't understand what you are trying to do. Can you give a distilled explanation for
dummies?
Regards, Ceki
At 14:10 26.06.2001 -0700, you wrote:
>Ummm, thanks . . but no, it didn't work.
>
>However, when I set it to INFO it works as expected.
>
>Does this imply that my subclass of Category or Priority is incorrect ?
>
>My subclass of Priority (actually called com.ebss.utilities.PPCSPriority)
>is included below.
>
>(Note: besides subclassing Category & Priority, I added/modified
>no other code.)
>
>Thanks
>
>///////////////////////////////////////////////////////////////////////////////////////////////////
/
>/**
> Clone and hack of org.apache.log4j.xml.exmples.PPCSPriority
> from log4j 1.1.1
>
> Purpose is to provide the NOTIFY and the FORCELOG priorities.
>*/
>
>package com.ebss.utilities ;
>
>import org.apache.log4j.Priority;
>
>
>/**
> This class introduces a new priority level called NOTIFY.
> - It will use a different appender.
>
> This class introduces a new priority level called FORCELOG.
> - It's output will NEVER be masked.
>
> */
>public class PPCSPriority extends Priority {
>
> static final int NOTIFY_INT = Priority.FATAL_INT + 1;
> static final int FORCELOG_INT = Priority.FATAL_INT + 2;
>
> private static String NOTIFY_STR = "NOTIFY";
> private static String FORCELOG_STR = "FORCELOG";
>
> public static final PPCSPriority NOTIFY = new PPCSPriority(NOTIFY_INT,
>NOTIFY_STR, 5);
> public static final PPCSPriority FORCELOG = new PPCSPriority(FORCELOG_INT,
>FORCELOG_STR, 5);
>
> protected
> PPCSPriority(int level, String strLevel, int syslogEquiv) {
> super(level, strLevel, syslogEquiv);
> }
> public
> static
> Priority toPriority(String sArg, Priority defaultValue) {
>
> if(sArg == null) {
> return defaultValue;
> }
> String stringVal = sArg.toUpperCase();
>
> if(stringVal.equals(NOTIFY_STR)) {
> return PPCSPriority.NOTIFY;
> } else if(stringVal.equals(FORCELOG_STR)) {
> return PPCSPriority.FORCELOG;
> }
>
> return Priority.toPriority(sArg, defaultValue);
> }
> public
> static
> Priority toPriority(int i) throws IllegalArgumentException {
> switch(i) {
> case NOTIFY_INT: return PPCSPriority.NOTIFY;
> case FORCELOG_INT: return PPCSPriority.FORCELOG;
> }
> return Priority.toPriority(i);
> }
>}
>///////////////////////////////////////////////////////////////////////////////////////////////////
/
>
>----- Original Message -----
>From: "Ceki Gülcü" <[EMAIL PROTECTED]>
>To: "LOG4J Users Mailing List" <[EMAIL PROTECTED]>
>Sent: Tuesday, June 26, 2001 1:05 PM
>Subject: Re: Problems with Filtering Extended Categories and Priorities
>
>
>
>Jay,
>
>Try <param name="PriorityToMatch" value="NOTIFY#your.Priority.subclass" />
>
>
>
>At 12:01 26.06.2001 -0700, you wrote:
>>I have extended Category (MyNewCategory) and have created 2
>>of my own priorities (NOTIFY and FORCELOG).
>>
>>I am using XML properties/config files.
>>
>>I can successfully filter (or set the logging priority) per class (aka category)
>>using the following:
>> <category name="a.b.c.d" class="MyNewCategory">
>> <priority value="NOTIFY" />
>> </category>
>>
>>However, the purpose for my NOTIFY priority was to separately filter
>>that and write it to a NT Event Log Appender. For now, I am using a
>>FileAppender to write these events to a separate log file.
>>
>>I have this appender configured as follows:
>>
>> <!-- Define the NOTIFY_TO_LOG appender -->
>> <appender name="NOTIFY_TO_LOG" class="org.apache.log4j.FileAppender">
>> <param name="File" value="log_notification_out.txt"/>
>>
>> <layout class="org.apache.log4j.PatternLayout">
>> <param name="ConversionPattern" value="%d{ISO8601} XXXX: %m%n"/>
>> </layout>
>>
>> <!-- Only write events with Priority=NOTIFY to this appender -->
>> <filter class="org.apache.log4j.varia.PriorityMatchFilter">
>> <param name="PriorityToMatch" value="NOTIFY" />
>> <param name="AcceptOnMatch" value="true" />
>> </filter>
>> <filter class="org.apache.log4j.varia.DenyAllFilter">
>> </filter>
>> </appender>
>>
>>If I change the PriorityToMatch value to INFO, then I get all my INFO logs
>>to go to this file using the format specified in the ConversionPattern.
>>Therefore, I suspect that my XML is setup properly.
>>
>>Inspection of org.apache.log4j.spi.LoggingEvent.java shows that it says
>>" <p>This class is of concern to those wishing to extend log4j. ".
>>
>>However, I am at a loss to understand how I should proceed.
>>
>>1) Should I *modify* the file and change all usages of Category to MyNewCategory ?
>>Would then I need to modify all the caller's to pass in a MyNewCategory ?
>>
>>2) Should I attempt to check if the given category object is really a MyNewCategory
>object ?
>>
>>3) Or more likely, I have no real clue !! <grin>
>>
>>Any and all help would be appreciated.
>>
>>Thanks
>>
>>
>>
>>----------------------------------------------------------------
>>Jay Riddell
>>Dorado Software
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: [EMAIL PROTECTED]
>>For additional commands, e-mail: [EMAIL PROTECTED]
>
>--
>Ceki Gülcü
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
--
Ceki Gülcü
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]