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 io.appium.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
28  public static void call(Object self, String method, Object... args) {
29    call(Log.DEBUG, self, method, args);
30  }
31
32  public static void call(int priority, Object self, String method, Object... args) {
33    if (Log.isLoggable(TAG, priority)) {
34      Log.d(
35          TAG,
36          String.format("Invoking %s.%s(%s)", self.getClass().getSimpleName(), method,
37              TextUtils.join(", ", args)));
38    }
39  }
40
41  public static void log(int priority, String msg) {
42    if (Log.isLoggable(TAG, priority)) {
43      Log.println(priority, TAG, msg);
44    }
45  }
46
47  public static void log(int priority, Throwable e) {
48    if (Log.isLoggable(TAG, priority)) {
49      Log.println(priority, TAG, Log.getStackTraceString(e));
50    }
51  }
52
53  public static void log(int priority, Throwable e, String msg) {
54    if (Log.isLoggable(TAG, priority)) {
55      Log.println(priority, TAG, msg + '\n' + Log.getStackTraceString(e));
56    }
57  }
58
59  public static void logfmt(int priority, String format, Object... args) {
60    if (Log.isLoggable(TAG, priority)) {
61      Log.println(priority, TAG, String.format(format, args));
62    }
63  }
64
65  public static void logfmt(int priority, Throwable e, String format, Object... args) {
66    if (Log.isLoggable(TAG, priority)) {
67      Log.println(priority, TAG, String.format(format, args) + '\n' + Log.getStackTraceString(e));
68    }
69  }
70
71  private Logs() {}
72}
73