1/* 2 * Copyright (C) 2013 DroidDriver committers 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 17package com.google.android.droiddriver.util; 18 19import android.text.TextUtils; 20import android.util.Log; 21 22/** 23 * Internal helper for logging. 24 */ 25public class Logs { 26 public static final String TAG = "DroidDriver"; 27 public static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); 28 29 public static void call(Object self, String method, Object... args) { 30 if (DEBUG) { 31 Log.d( 32 TAG, 33 String.format("Invoking %s.%s(%s)", self.getClass().getSimpleName(), method, 34 TextUtils.join(", ", args))); 35 } 36 } 37 38 public static void log(int priority, String msg) { 39 if (Log.isLoggable(TAG, priority)) { 40 Log.println(priority, TAG, msg); 41 } 42 } 43 44 public static void log(int priority, Throwable e) { 45 if (Log.isLoggable(TAG, priority)) { 46 Log.println(priority, TAG, Log.getStackTraceString(e)); 47 } 48 } 49 50 public static void log(int priority, Throwable e, String msg) { 51 if (Log.isLoggable(TAG, priority)) { 52 Log.println(priority, TAG, msg + '\n' + Log.getStackTraceString(e)); 53 } 54 } 55 56 public static void logfmt(int priority, String format, Object... args) { 57 if (Log.isLoggable(TAG, priority)) { 58 Log.println(priority, TAG, String.format(format, args)); 59 } 60 } 61 62 public static void logfmt(int priority, Throwable e, String format, Object... args) { 63 if (Log.isLoggable(TAG, priority)) { 64 Log.println(priority, TAG, String.format(format, args) + '\n' + Log.getStackTraceString(e)); 65 } 66 } 67 68 private Logs() {} 69} 70