Home | History | Annotate | Download | only in log
      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.Collection;
     23 import java.util.Map;
     24 
     25 /**
     26  * An interface for a {@link ILogOutput} singleton logger that multiplexes and manages different
     27  * loggers.
     28  */
     29 public interface ILogRegistry extends ILogOutput {
     30 
     31     /** Events that are useful to be logged */
     32     public enum EventType {
     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     }
     42 
     43     /**
     44      * Set the log level display for the global log
     45      *
     46      * @param logLevel the {@link LogLevel} to use
     47      */
     48     public void setGlobalLogDisplayLevel(LogLevel logLevel);
     49 
     50     /**
     51      * Set the log tags to display for the global log
     52      */
     53     public void setGlobalLogTagDisplay(Collection<String> logTagsDisplay);
     54 
     55     /**
     56      * Returns current log level display for the global log
     57      *
     58      * @return logLevel the {@link LogLevel} to use
     59      */
     60     public LogLevel getGlobalLogDisplayLevel();
     61 
     62     /**
     63      * Registers the logger as the instance to use for the current thread.
     64      */
     65     public void registerLogger(ILeveledLogOutput log);
     66 
     67     /**
     68      * Unregisters the current logger in effect for the current thread.
     69      */
     70     public void unregisterLogger();
     71 
     72     /**
     73      * Dumps the entire contents of a {@link ILeveledLogOutput} logger to the global log.
     74      * <p/>
     75      * This is useful in scenarios where you know the logger's output won't be saved permanently,
     76      * yet you want the contents to be saved somewhere and not lost.
     77      *
     78      * @param log
     79      */
     80     public void dumpToGlobalLog(ILeveledLogOutput log);
     81 
     82     /**
     83      * Closes and removes all logs being managed by this LogRegistry.
     84      */
     85     public void closeAndRemoveAllLogs();
     86 
     87     /** Saves all the global loggers contents to tmp files. */
     88     public void saveGlobalLog();
     89 
     90     /**
     91      * Call this method to log an event from a type with the associated information in the map. Time
     92      * of the event is automatically added.
     93      *
     94      * @param logLevel the {@link LogLevel} to be printed.
     95      * @param event the {@link ILogRegistry.EventType} of the event to log.
     96      * @param args the map of arguments to be added to the log entry to get more details on the
     97      *     event.
     98      */
     99     public void logEvent(LogLevel logLevel, EventType event, Map<String, String> args);
    100 
    101     /** Diagnosis method to dump all logs to files. */
    102     public void dumpLogs();
    103 
    104 }
    105