LogRegistry

public class LogRegistry
extends Object implements ILogRegistry

java.lang.Object
   ↳ com.android.tradefed.log.LogRegistry


A ILogRegistry implementation that multiplexes and manages different loggers, using the appropriate one based on the ThreadGroup of the thread making the call.

Note that the registry hashes on the ThreadGroup in which a thread belongs. If a thread is spawned with its own explicitly-supplied ThreadGroup, it will not inherit the parent thread's logger, and thus will need to register its own logger with the LogRegistry if it wants to log output.

Summary

Public methods

void closeAndRemoveAllLogs()

Closes and removes all logs being managed by this LogRegistry.

void dumpLogs()

Diagnosis method to dump all logs to files.

void dumpLogsToDir(File dir)

Save the log data to files in the specified directory.

void dumpToGlobalLog(ILeveledLogOutput log)

Dumps the entire contents of a ILeveledLogOutput logger to the global log.

Log.LogLevel getGlobalLogDisplayLevel()

Returns current log level display for the global log

static ILogRegistry getLogRegistry()

Get the LogRegistry instance

ILeveledLogOutput getLogger()

Gets the underlying logger associated with this thread.

void logEvent(Log.LogLevel logLevel, ILogRegistry.EventType event, args)

Call this method to log an event from a type with the associated information in the map.

void printAndPromptLog(Log.LogLevel logLevel, String tag, String message)

Sent when a log message needs to be printed, and, if possible, displayed to the user in a dialog box.

void printLog(Log.LogLevel logLevel, String tag, String message)

Sent when a log message needs to be printed.

void registerLogger(ILeveledLogOutput log)

Registers the logger as the instance to use for the current thread.

static void resetLocalGroup()

Resets the localized context.

void saveGlobalLog()

Saves all the global loggers contents to tmp files.

void setGlobalLogDisplayLevel(Log.LogLevel logLevel)

Set the log level display for the global log

static void setLocalGroup(ThreadGroup tg)

Tracks a localized context when using the properties inside the gRPC server

void unregisterLogger()

Unregisters the current logger in effect for the current thread.

Public methods

closeAndRemoveAllLogs

public void closeAndRemoveAllLogs ()

Closes and removes all logs being managed by this LogRegistry.

dumpLogs

public void dumpLogs ()

Diagnosis method to dump all logs to files.

dumpLogsToDir

public void dumpLogsToDir (File dir)

Save the log data to files in the specified directory.

Parameters
dir File: directory to save file, can be null, file will be saved in tmp directory.

dumpToGlobalLog

public void dumpToGlobalLog (ILeveledLogOutput log)

Dumps the entire contents of a ILeveledLogOutput logger to the global log.

This is useful in scenarios where you know the logger's output won't be saved permanently, yet you want the contents to be saved somewhere and not lost.

getGlobalLogDisplayLevel

public Log.LogLevel getGlobalLogDisplayLevel ()

Returns current log level display for the global log

Returns
Log.LogLevel logLevel the LogLevel to use

getLogRegistry

public static ILogRegistry getLogRegistry ()

Get the LogRegistry instance

Returns
ILogRegistry a LogRegistry that can be used to register, get, write to, and close logs

getLogger

public ILeveledLogOutput getLogger ()

Gets the underlying logger associated with this thread.

Returns
ILeveledLogOutput the logger for this thread group, or the global logger if one has not been registered for the thread group.

logEvent

public void logEvent (Log.LogLevel logLevel, 
                ILogRegistry.EventType event, 
                 args)

Call this method to log an event from a type with the associated information in the map. Time of the event is automatically added.

Parameters
logLevel Log.LogLevel: the LogLevel to be printed.

event ILogRegistry.EventType: the ILogRegistry.EventType of the event to log.

args : the map of arguments to be added to the log entry to get more details on the event.

printAndPromptLog

public void printAndPromptLog (Log.LogLevel logLevel, 
                String tag, 
                String message)

Sent when a log message needs to be printed, and, if possible, displayed to the user in a dialog box.

Parameters
logLevel Log.LogLevel: The LogLevel enum representing the priority of the message.

tag String: The tag associated with the message.

message String: The message to display.

printLog

public void printLog (Log.LogLevel logLevel, 
                String tag, 
                String message)

Sent when a log message needs to be printed.

Parameters
logLevel Log.LogLevel: The LogLevel enum representing the priority of the message.

tag String: The tag associated with the message.

message String: The message to display.

registerLogger

public void registerLogger (ILeveledLogOutput log)

Registers the logger as the instance to use for the current thread.

Parameters
log ILeveledLogOutput

resetLocalGroup

public static void resetLocalGroup ()

Resets the localized context.

saveGlobalLog

public void saveGlobalLog ()

Saves all the global loggers contents to tmp files.

setGlobalLogDisplayLevel

public void setGlobalLogDisplayLevel (Log.LogLevel logLevel)

Set the log level display for the global log

Parameters
logLevel Log.LogLevel: the LogLevel to use

setLocalGroup

public static void setLocalGroup (ThreadGroup tg)

Tracks a localized context when using the properties inside the gRPC server

Parameters
tg ThreadGroup

unregisterLogger

public void unregisterLogger ()

Unregisters the current logger in effect for the current thread.