package org.jboss.logging;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
final class JDKLogger extends Logger {
private static final long serialVersionUID = 2563174097983721393L;
@SuppressWarnings({ "NonConstantLogger" })
private transient final java.util.logging.Logger logger;
public JDKLogger(final String name) {
super(name);
logger = java.util.logging.Logger.getLogger(name);
}
protected void doLog(final Level level, final String loggerClassName, final Object message, final Object[] parameters, final Throwable thrown) {
if (isEnabled(level)) try {
final JBossLogRecord rec = new JBossLogRecord(translate(level), String.valueOf(message), loggerClassName);
if (thrown != null) rec.setThrown(thrown);
rec.setLoggerName(getName());
rec.setParameters(parameters);
rec.setResourceBundleName(logger.getResourceBundleName());
rec.setResourceBundle(logger.getResourceBundle());
logger.log(rec);
} catch (Throwable ignored) {}
}
protected void doLogf(final Level level, final String loggerClassName, String format, final Object[] parameters, final Throwable thrown) {
if (isEnabled(level)) try {
final ResourceBundle resourceBundle = logger.getResourceBundle();
if (resourceBundle != null) try {
format = resourceBundle.getString(format);
} catch (MissingResourceException e) {
}
final String msg = parameters == null ? String.format(format) : String.format(format, parameters);
final JBossLogRecord rec = new JBossLogRecord(translate(level), msg, loggerClassName);
if (thrown != null) rec.setThrown(thrown);
rec.setLoggerName(getName());
rec.setResourceBundleName(logger.getResourceBundleName());
rec.setResourceBundle(null);
rec.setParameters(null);
logger.log(rec);
} catch (Throwable ignored) {}
}
private static java.util.logging.Level translate(final Level level) {
if (level == Level.TRACE) {
return JDKLevel.TRACE;
} else if (level == Level.DEBUG) {
return JDKLevel.DEBUG;
}
return infoOrHigher(level);
}
private static java.util.logging.Level infoOrHigher(final Level level) {
if (level == Level.INFO) {
return JDKLevel.INFO;
} else if (level == Level.WARN) {
return JDKLevel.WARN;
} else if (level == Level.ERROR) {
return JDKLevel.ERROR;
} else if (level == Level.FATAL) {
return JDKLevel.FATAL;
}
return JDKLevel.ALL;
}
public boolean isEnabled(final Level level) {
return logger.isLoggable(translate(level));
}
}