AndroidHandlerpublic class AndroidHandler extends Handler implements dalvik.system.DalvikLogHandlerImplements a {@link java.util.logging.Logger} handler that writes to the Android log. The
implementation is rather straightforward. The name of the logger serves as
the log tag. Only the log levels need to be converted appropriately. For
this purpose, the following mapping is being used:
logger level |
Android level |
SEVERE
|
ERROR
|
WARNING
|
WARN
|
INFO
|
INFO
|
CONFIG
|
DEBUG
|
FINE, FINER, FINEST
|
VERBOSE
|
|
Fields Summary |
---|
private static final Formatter | THE_FORMATTERHolds the formatter for all Android log handlers. |
Constructors Summary |
---|
public AndroidHandler()Constructs a new instance of the Android log handler.
setFormatter(THE_FORMATTER);
|
Methods Summary |
---|
public void | close()
// No need to close, but must implement abstract method.
| public void | flush()
// No need to flush, but must implement abstract method.
| static int | getAndroidLevel(java.util.logging.Level level)Converts a {@link java.util.logging.Logger} logging level into an Android one.
int value = level.intValue();
if (value >= 1000) { // SEVERE
return Log.ERROR;
} else if (value >= 900) { // WARNING
return Log.WARN;
} else if (value >= 800) { // INFO
return Log.INFO;
} else {
return Log.DEBUG;
}
| public void | publish(java.util.logging.LogRecord record)
int level = getAndroidLevel(record.getLevel());
String tag = DalvikLogging.loggerNameToTag(record.getLoggerName());
if (!Log.isLoggable(tag, level)) {
return;
}
try {
String message = getFormatter().format(record);
Log.println(level, tag, message);
} catch (RuntimeException e) {
Log.e("AndroidHandler", "Error logging message.", e);
}
| public void | publish(java.util.logging.Logger source, java.lang.String tag, java.util.logging.Level level, java.lang.String message)
// TODO: avoid ducking into native 2x; we aren't saving any formatter calls
int priority = getAndroidLevel(level);
if (!Log.isLoggable(tag, priority)) {
return;
}
try {
Log.println(priority, tag, message);
} catch (RuntimeException e) {
Log.e("AndroidHandler", "Error logging message.", e);
}
|
|