Details
-
Improvement
-
Resolution: Unresolved
-
None
-
1.7.x
-
None
-
Operating System: Windows XP
Platform: PC
-
enhancement
-
P1
-
292
Description
I suppose to implement a custom JUL-LogManager that switches off the JUL configuration completely:
public class Slf4jLogManager extends LogManager
{
public Slf4jLogManager()
{
}
@Override
public void readConfiguration() throws IOException, SecurityException
{
}
@Override
public void readConfiguration(InputStream ins) throws IOException,
SecurityException
{
}
@Override
public synchronized boolean addLogger(Logger logger)
}
public class Slf4jLoggerAdapter
{
private final String name;
private volatile Logger logger;
public Slf4jLoggerAdapter(String name)
{ this.name = name; } private Logger resolve()
{
Logger logger = this.logger;
if (logger == null)
return logger;
}
private Logger demandLogger()
{ return LoggerFactory.getLogger(name); } public Level getLevel()
{
org.slf4j.Logger logger = resolve();
Level level;
if (logger.isTraceEnabled())
else if (logger.isDebugEnabled())
{ level = Level.FINER; }else if (logger.isInfoEnabled())
{ level = Level.INFO; }else if (logger.isWarnEnabled())
{ level = Level.WARNING; }else if (logger.isErrorEnabled())
{ level = Level.SEVERE; }else
{ level = Level.OFF; } return level;
}
public boolean isLoggable(Level level)
{ return getLevel().intValue() <= level.intValue(); }public boolean isSevereEnabled()
{ return resolve().isErrorEnabled(); } // ...
}
public class Slf4jLogger extends Logger
{
private static final Handler BRIDGE_HANDLER = new SLF4JBridgeHandler();
private final Slf4jLoggerAdapter adapter;
public Slf4jLogger(String name, String resourceBundleName)
{ super(name, resourceBundleName); adapter = new Slf4jLoggerAdapter(name); super.setLevel(Level.ALL); super.addHandler(BRIDGE_HANDLER); super.setUseParentHandlers(false); } @Override
public Level getLevel()
@Override
public boolean isLoggable(Level level)
@Override
public void severe(String msg)
{
if (adapter.isSevereEnabled())
}
// ...
}