FileDocCategorySizeDatePackage
AndroidHandler.javaAPI DocAndroid 5.1 API4697Thu Mar 12 22:22:10 GMT 2015com.android.internal.logging

AndroidHandler

public class AndroidHandler extends Handler implements dalvik.system.DalvikLogHandler
Implements 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_FORMATTER
Holds 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 voidclose()

        // No need to close, but must implement abstract method.
    
public voidflush()

        // No need to flush, but must implement abstract method.
    
static intgetAndroidLevel(java.util.logging.Level level)
Converts a {@link java.util.logging.Logger} logging level into an Android one.

param
level The {@link java.util.logging.Logger} logging level.
return
The resulting Android logging level.

        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 voidpublish(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 voidpublish(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);
        }