Home | History | Annotate | Download | only in monkey
      1 /*
      2  * Copyright (C) 2016 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.commands.monkey;
     18 
     19 import android.util.Log;
     20 
     21 public abstract class Logger {
     22     private static final String TAG = "Monkey";
     23 
     24     public static Logger out = new Logger() {
     25         public void println(String s) {
     26             if (stdout) {
     27                 System.out.println(s);
     28             }
     29             if (logcat) {
     30                 Log.i(TAG, s);
     31             }
     32         }
     33     };
     34     public static Logger err = new Logger() {
     35         public void println(String s) {
     36             if (stdout) {
     37                 System.err.println(s);
     38             }
     39             if (logcat) {
     40                 Log.w(TAG, s);
     41             }
     42         }
     43     };
     44 
     45     public static boolean stdout = true;
     46     public static boolean logcat = true;
     47 
     48     public abstract void println(String s);
     49 
     50     /**
     51      * Log an exception (throwable) at the ERROR level with an accompanying message.
     52      *
     53      * @param msg The message accompanying the exception.
     54      * @param t The exception (throwable) to log.
     55      */
     56     public static void error(String msg, Throwable t) {
     57         err.println(msg);
     58         err.println(Log.getStackTraceString(t));
     59     }
     60 }
     61