FileDocCategorySizeDatePackage
HdmiLogger.javaAPI DocAndroid 5.1 API4628Thu Mar 12 22:22:42 GMT 2015com.android.server.hdmi

HdmiLogger

public final class HdmiLogger extends Object
A logger that prevents spammy log. For the same log message, it logs once every 20seconds. This class is not thread-safe.

For convenience, use single character prefix for all messages. Here are common acronyms

  • [T]: Timout
  • [R]: Received message
  • [S]: Sent message
  • [P]: Device polling result

Fields Summary
private static final String
TAG
private static final long
ERROR_LOG_DURATTION_MILLIS
private static final boolean
IS_USER_BUILD
private static final ThreadLocal
sLogger
private final HashMap
mWarningTimingCache
private final HashMap
mErrorTimingCache
Constructors Summary
private HdmiLogger()


      
    
Methods Summary
private static java.lang.StringbuildMessage(java.lang.String message, android.util.Pair timing)

        return new StringBuilder()
                .append("[").append(timing == null ? 1 : timing.second).append("]:")
                .append(message).toString();
    
static final voiddebug(java.lang.String logMessage, java.lang.Object objs)

        getLogger().debugInternal(toLogString(logMessage, objs));
    
private voiddebugInternal(java.lang.String logMessage)

        if (true || IS_USER_BUILD) {
            return;
        }
        Slog.d(TAG, logMessage);
    
static final voiderror(java.lang.String logMessage, java.lang.Object objs)

        getLogger().errorInternal(toLogString(logMessage, objs));
    
private voiderrorInternal(java.lang.String logMessage)

        String log = updateLog(mErrorTimingCache, logMessage);
        if (!log.isEmpty()) {
            Slog.e(TAG, log);
        }
    
private static com.android.server.hdmi.HdmiLoggergetLogger()

        HdmiLogger logger = sLogger.get();
        if (logger == null) {
            logger = new HdmiLogger();
            sLogger.set(logger);
        }
        return logger;
    
private static voidincreaseLogCount(java.util.HashMap cache, java.lang.String message)

        Pair<Long, Integer> timing = cache.get(message);
        if (timing != null) {
            cache.put(message, new Pair<>(timing.first, timing.second + 1));
        }
    
private static booleanshouldLogNow(android.util.Pair timing, long curTime)

        return timing == null || curTime - timing.first > ERROR_LOG_DURATTION_MILLIS;
    
private static final java.lang.StringtoLogString(java.lang.String logMessage, java.lang.Object[] objs)

        if (objs.length > 0) {
            return String.format(logMessage, objs);
        } else {
            return logMessage;
        }
    
private static java.lang.StringupdateLog(java.util.HashMap cache, java.lang.String logMessage)

        long curTime = SystemClock.uptimeMillis();
        Pair<Long, Integer> timing = cache.get(logMessage);
        if (shouldLogNow(timing, curTime)) {
            String log = buildMessage(logMessage, timing);
            cache.put(logMessage, new Pair<>(curTime, 1));
            return log;
        } else {
            increaseLogCount(cache, logMessage);
        }
        return "";
    
static final voidwarning(java.lang.String logMessage, java.lang.Object objs)

        getLogger().warningInternal(toLogString(logMessage, objs));
    
private voidwarningInternal(java.lang.String logMessage)

        String log = updateLog(mWarningTimingCache, logMessage);
        if (!log.isEmpty()) {
            Slog.w(TAG, log);
        }