• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.tradefed.log;
18 
19 import com.android.ddmlib.Log.ILogOutput;
20 import com.android.ddmlib.Log.LogLevel;
21 
22 import java.util.Map;
23 
24 /**
25  * An interface for a {@link ILogOutput} singleton logger that multiplexes and manages different
26  * loggers.
27  */
28 public interface ILogRegistry extends ILogOutput {
29 
30     /** Events that are useful to be logged */
31     public enum EventType {
32         DEVICE_CONNECTED,
33         DEVICE_CONNECTED_OFFLINE,
34         DEVICE_DISCONNECTED,
35         INVOCATION_START,
36         INVOCATION_END,
37         HEAP_MEMORY,
38         SHARD_POLLER_EARLY_TERMINATION,
39         MODULE_DEVICE_NOT_AVAILABLE,
40         UNEXPECTED_EXCEPTION,
41     }
42 
43     /**
44      * Set the log level display for the global log
45      *
46      * @param logLevel the {@link LogLevel} to use
47      */
setGlobalLogDisplayLevel(LogLevel logLevel)48     public void setGlobalLogDisplayLevel(LogLevel logLevel);
49 
50     /**
51      * Returns current log level display for the global log
52      *
53      * @return logLevel the {@link LogLevel} to use
54      */
getGlobalLogDisplayLevel()55     public LogLevel getGlobalLogDisplayLevel();
56 
57     /**
58      * Registers the logger as the instance to use for the current thread.
59      */
registerLogger(ILeveledLogOutput log)60     public void registerLogger(ILeveledLogOutput log);
61 
62     /**
63      * Unregisters the current logger in effect for the current thread.
64      */
unregisterLogger()65     public void unregisterLogger();
66 
67     /**
68      * Dumps the entire contents of a {@link ILeveledLogOutput} logger to the global log.
69      * <p/>
70      * This is useful in scenarios where you know the logger's output won't be saved permanently,
71      * yet you want the contents to be saved somewhere and not lost.
72      *
73      * @param log
74      */
dumpToGlobalLog(ILeveledLogOutput log)75     public void dumpToGlobalLog(ILeveledLogOutput log);
76 
77     /**
78      * Closes and removes all logs being managed by this LogRegistry.
79      */
closeAndRemoveAllLogs()80     public void closeAndRemoveAllLogs();
81 
82     /** Saves all the global loggers contents to tmp files. */
saveGlobalLog()83     public void saveGlobalLog();
84 
85     /**
86      * Call this method to log an event from a type with the associated information in the map. Time
87      * of the event is automatically added.
88      *
89      * @param logLevel the {@link LogLevel} to be printed.
90      * @param event the {@link ILogRegistry.EventType} of the event to log.
91      * @param args the map of arguments to be added to the log entry to get more details on the
92      *     event.
93      */
logEvent(LogLevel logLevel, EventType event, Map<String, String> args)94     public void logEvent(LogLevel logLevel, EventType event, Map<String, String> args);
95 
96     /** Diagnosis method to dump all logs to files. */
dumpLogs()97     public void dumpLogs();
98 
99 }
100