You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by cz...@apache.org on 2004/02/29 18:57:11 UTC
cvs commit: avalon-logkit/src/java/org/apache/log/output PriorityFilteringTarget.java AbstractWrappingTarget.java AsyncLogTarget.java
cziegeler 2004/02/29 09:57:11
Modified: src/java/org/apache/log/output AbstractWrappingTarget.java
AsyncLogTarget.java
Added: src/java/org/apache/log/output PriorityFilteringTarget.java
Log:
Add PriorityFilteringTarget to allow same features as the deprecated PriorityFilter
Revision Changes Path
1.6 +8 -0 avalon-logkit/src/java/org/apache/log/output/AbstractWrappingTarget.java
Index: AbstractWrappingTarget.java
===================================================================
RCS file: /home/cvs/avalon-logkit/src/java/org/apache/log/output/AbstractWrappingTarget.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- AbstractWrappingTarget.java 28 Feb 2004 11:31:25 -0000 1.5
+++ AbstractWrappingTarget.java 29 Feb 2004 17:57:11 -0000 1.6
@@ -68,4 +68,12 @@
( (Closeable)m_wrappedLogTarget ).close();
}
}
+
+ /**
+ * Return the target for subclasses
+ */
+ protected final LogTarget getLogTarget()
+ {
+ return m_wrappedLogTarget;
+ }
}
1.20 +3 -5 avalon-logkit/src/java/org/apache/log/output/AsyncLogTarget.java
Index: AsyncLogTarget.java
===================================================================
RCS file: /home/cvs/avalon-logkit/src/java/org/apache/log/output/AsyncLogTarget.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- AsyncLogTarget.java 28 Feb 2004 11:31:25 -0000 1.19
+++ AsyncLogTarget.java 29 Feb 2004 17:57:11 -0000 1.20
@@ -46,7 +46,6 @@
{
private final LinkedList m_list;
private final int m_queueSize;
- private final LogTarget m_logTarget;
/**
* Creation of a new async log target.
@@ -88,7 +87,6 @@
public AsyncLogTarget( final LogTarget logTarget, final int queueSize, final boolean closeTarget )
{
super( logTarget, closeTarget );
- m_logTarget = logTarget;
m_list = new LinkedList();
m_queueSize = queueSize;
open();
@@ -103,9 +101,9 @@
{
super.setErrorHandler( errorHandler );
- if( m_logTarget instanceof ErrorAware )
+ if( this.getLogTarget() instanceof ErrorAware )
{
- ( (ErrorAware)m_logTarget ).setErrorHandler( errorHandler );
+ ( (ErrorAware)this.getLogTarget() ).setErrorHandler( errorHandler );
}
}
@@ -201,7 +199,7 @@
try
{
//actually process an event
- m_logTarget.processEvent( event );
+ this.getLogTarget().processEvent( event );
}
catch( final Throwable throwable )
{
1.1 avalon-logkit/src/java/org/apache/log/output/PriorityFilteringTarget.java
Index: PriorityFilteringTarget.java
===================================================================
/*
* Copyright 2004 The Apache Software Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.log.output;
import org.apache.log.LogEvent;
import org.apache.log.LogTarget;
import org.apache.log.Priority;
import org.apache.log.util.Closeable;
/**
* This is a priority filtering target that forwards only requests
* to other (wrapped) targets that have the same or a higher
* priority.
*
* @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
*/
public class PriorityFilteringTarget
extends AbstractTarget
{
private final Priority m_priority;
private final boolean m_closeWrapped;
/** Log targets in filter chain */
private LogTarget m_targets[];
/**
* @param Priority The priority used to filter
* @param closeWrappedTarget see AbstractWrappingTarget
*/
public PriorityFilteringTarget(Priority priority,
boolean closeWrappedTarget)
{
m_priority = priority;
m_closeWrapped = closeWrappedTarget;
}
/**
* @param Priority The priority used to filter
*/
public PriorityFilteringTarget(Priority priority)
{
m_priority = priority;
m_closeWrapped = false;
}
/**
* Add a new target to output chain.
*
* @param target the target
*/
public void addTarget( final LogTarget target )
{
if( null == m_targets )
{
m_targets = new LogTarget[]{target};
}
else
{
final LogTarget oldTargets[] = m_targets;
m_targets = new LogTarget[ oldTargets.length + 1 ];
System.arraycopy( oldTargets, 0, m_targets, 0, oldTargets.length );
m_targets[ m_targets.length - 1 ] = target;
}
}
/* (non-Javadoc)
* @see org.apache.log.output.AbstractTarget#doProcessEvent(org.apache.log.LogEvent)
*/
protected void doProcessEvent(LogEvent event) throws Exception
{
if ( event != null
&& m_targets != null
&& !event.getPriority().isLower(m_priority) )
{
for( int i = 0; i < m_targets.length; i++ )
{
m_targets[ i ].processEvent( event );
}
}
}
/* (non-Javadoc)
* @see org.apache.log.util.Closeable#close()
*/
public void close()
{
super.close();
if( m_closeWrapped && m_targets != null )
{
for( int i = 0; i < m_targets.length; i++ )
{
if ( m_targets[i] instanceof Closeable )
{
( (Closeable)m_targets[i] ).close();
}
}
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org