• 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.tradefed.log.Log.ILogOutput;
20 import com.android.tradefed.log.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         TRADEFED_STARTED,
33         DEVICE_CONNECTED,
34         DEVICE_CONNECTED_OFFLINE,
35         DEVICE_DISCONNECTED,
36         INVOCATION_START,
37         INVOCATION_END,
38         HEAP_MEMORY,
39         SHARD_POLLER_EARLY_TERMINATION,
40         MODULE_DEVICE_NOT_AVAILABLE,
41         UNEXPECTED_EXCEPTION,
42     }
43 
44     /**
45      * Set the log level display for the global log
46      *
47      * @param logLevel the {@link LogLevel} to use
48      */
setGlobalLogDisplayLevel(LogLevel logLevel)49     public void setGlobalLogDisplayLevel(LogLevel logLevel);
50 
51     /**
52      * Returns current log level display for the global log
53      *
54      * @return logLevel the {@link LogLevel} to use
55      */
getGlobalLogDisplayLevel()56     public LogLevel getGlobalLogDisplayLevel();
57 
58     /**
59      * Registers the logger as the instance to use for the current thread.
60      */
registerLogger(ILeveledLogOutput log)61     public void registerLogger(ILeveledLogOutput log);
62 
63     /**
64      * Unregisters the current logger in effect for the current thread.
65      */
unregisterLogger()66     public void unregisterLogger();
67 
68     /**
69      * Dumps the entire contents of a {@link ILeveledLogOutput} logger to the global log.
70      * <p/>
71      * This is useful in scenarios where you know the logger's output won't be saved permanently,
72      * yet you want the contents to be saved somewhere and not lost.
73      *
74      * @param log
75      */
dumpToGlobalLog(ILeveledLogOutput log)76     public void dumpToGlobalLog(ILeveledLogOutput log);
77 
78     /**
79      * Closes and removes all logs being managed by this LogRegistry.
80      */
closeAndRemoveAllLogs()81     public void closeAndRemoveAllLogs();
82 
83     /** Saves all the global loggers contents to tmp files. */
saveGlobalLog()84     public void saveGlobalLog();
85 
86     /**
87      * Call this method to log an event from a type with the associated information in the map. Time
88      * of the event is automatically added.
89      *
90      * @param logLevel the {@link LogLevel} to be printed.
91      * @param event the {@link ILogRegistry.EventType} of the event to log.
92      * @param args the map of arguments to be added to the log entry to get more details on the
93      *     event.
94      */
logEvent(LogLevel logLevel, EventType event, Map<String, String> args)95     public void logEvent(LogLevel logLevel, EventType event, Map<String, String> args);
96 
97     /** Diagnosis method to dump all logs to files. */
dumpLogs()98     public void dumpLogs();
99 
100 }
101