Actually, let's just pass the level index down to the logger implementation (as
Ray suggested). It's less code and skips the casts entirely. git-svn-id: https://samskivert.googlecode.com/svn/trunk@2906 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -21,9 +21,6 @@
|
||||
package com.samskivert.util;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.Level;
|
||||
|
||||
@@ -113,25 +110,19 @@ public class JDK14Logger implements Logger.Factory
|
||||
}
|
||||
|
||||
@Override // from Logger
|
||||
protected List<?> getLevels ()
|
||||
protected boolean shouldLog (int levIdx)
|
||||
{
|
||||
return LEVELS;
|
||||
return _impl.isLoggable(LEVELS[levIdx]);
|
||||
}
|
||||
|
||||
@Override // from Logger
|
||||
protected boolean shouldLog (Object level)
|
||||
protected void doLog (int levIdx, String formatted, Throwable throwable)
|
||||
{
|
||||
return _impl.isLoggable((Level)level);
|
||||
}
|
||||
|
||||
@Override // from Logger
|
||||
protected void doLog (Object level, String formatted, Throwable throwable)
|
||||
{
|
||||
_impl.log((Level)level, formatted, throwable);
|
||||
_impl.log(LEVELS[levIdx], formatted, throwable);
|
||||
}
|
||||
|
||||
protected java.util.logging.Logger _impl;
|
||||
protected static final List<Level> LEVELS = Collections.unmodifiableList(Arrays.asList(
|
||||
Level.FINE, Level.INFO, Level.WARNING, Level.SEVERE));
|
||||
protected static final Level[] LEVELS = {
|
||||
Level.FINE, Level.INFO, Level.WARNING, Level.SEVERE };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,10 +20,6 @@
|
||||
|
||||
package com.samskivert.util;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Level;
|
||||
|
||||
/**
|
||||
@@ -56,26 +52,20 @@ public class Log4JLogger implements Logger.Factory
|
||||
}
|
||||
|
||||
@Override // from Logger
|
||||
protected List<?> getLevels ()
|
||||
protected boolean shouldLog (int levIdx)
|
||||
{
|
||||
return LEVELS;
|
||||
return _impl.isEnabledFor(LEVELS[levIdx]);
|
||||
}
|
||||
|
||||
@Override // from Logger
|
||||
protected boolean shouldLog (Object level)
|
||||
protected void doLog (int levIdx, String formatted, Throwable throwable)
|
||||
{
|
||||
return _impl.isEnabledFor((Level)level);
|
||||
}
|
||||
|
||||
@Override // from Logger
|
||||
protected void doLog (Object level, String formatted, Throwable throwable)
|
||||
{
|
||||
_impl.log(_self, (Level)level, formatted, throwable);
|
||||
_impl.log(_self, LEVELS[levIdx], formatted, throwable);
|
||||
}
|
||||
|
||||
protected final org.apache.log4j.Logger _impl;
|
||||
protected final String _self = getClass().getName();
|
||||
protected static final List<Level> LEVELS = Collections.unmodifiableList(Arrays.asList(
|
||||
Level.DEBUG, Level.INFO, Level.WARN, Level.ERROR));
|
||||
protected static final Level[] LEVELS = {
|
||||
Level.DEBUG, Level.INFO, Level.WARN, Level.ERROR };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,8 +20,6 @@
|
||||
|
||||
package com.samskivert.util;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Provides logging services to this library and others which depend on this library in such a way
|
||||
* that they can be used in a larger project and easily be made to log to the logging framework in
|
||||
@@ -136,8 +134,7 @@ public abstract class Logger
|
||||
|
||||
protected void doLog (int levIdx, Object message, Object[] args)
|
||||
{
|
||||
Object level = getLevels().get(levIdx);
|
||||
if (!shouldLog(level)) {
|
||||
if (!shouldLog(levIdx)) {
|
||||
return;
|
||||
}
|
||||
Throwable err = null;
|
||||
@@ -170,19 +167,15 @@ public abstract class Logger
|
||||
}
|
||||
msg = buf.append(']').toString();
|
||||
}
|
||||
doLog(level, msg, err);
|
||||
doLog(levIdx, msg, err);
|
||||
}
|
||||
|
||||
/** Returns the logger implementation specific level constants in a specific order: debug,
|
||||
* info, warn, error. */
|
||||
protected abstract List<?> getLevels ();
|
||||
|
||||
/** Returns true if a log message at the specified level should be logged. */
|
||||
protected abstract boolean shouldLog (Object level);
|
||||
protected abstract boolean shouldLog (int levIdx);
|
||||
|
||||
/** Performs the actual logging of a message at the specified level.
|
||||
* @param throwable an exception that accompanies this message or null. */
|
||||
protected abstract void doLog (Object level, String formatted, Throwable throwable);
|
||||
protected abstract void doLog (int levIdx, String formatted, Throwable throwable);
|
||||
|
||||
/**
|
||||
* Called at static initialization time. Selects and initializes our logging backend.
|
||||
|
||||
Reference in New Issue
Block a user