1 /* 2 * Copyright (C) 2014 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 package com.example.android.musicservicedemo.utils; 17 18 import android.util.Log; 19 20 public class LogHelper { v(String tag, Object... messages)21 public final static void v(String tag, Object... messages) { 22 log(tag, Log.VERBOSE, null, messages); 23 } 24 d(String tag, Object... messages)25 public final static void d(String tag, Object... messages) { 26 log(tag, Log.DEBUG, null, messages); 27 } 28 i(String tag, Object... messages)29 public final static void i(String tag, Object... messages) { 30 log(tag, Log.INFO, null, messages); 31 } 32 w(String tag, Object... messages)33 public final static void w(String tag, Object... messages) { 34 log(tag, Log.WARN, null, messages); 35 } 36 w(String tag, Throwable t, Object... messages)37 public final static void w(String tag, Throwable t, Object... messages) { 38 log(tag, Log.WARN, t, messages); 39 } 40 e(String tag, Object... messages)41 public final static void e(String tag, Object... messages) { 42 log(tag, Log.ERROR, null, messages); 43 } 44 e(String tag, Throwable t, Object... messages)45 public final static void e(String tag, Throwable t, Object... messages) { 46 log(tag, Log.ERROR, t, messages); 47 } 48 log(String tag, int level, Throwable t, Object... messages)49 public final static void log(String tag, int level, Throwable t, Object... messages) { 50 if (messages != null && Log.isLoggable(tag, level)) { 51 String message = null; 52 if (messages.length == 1) { 53 message = messages[0] == null ? null : messages[0].toString(); 54 } else { 55 StringBuilder sb = new StringBuilder(); 56 for (Object m: messages) { 57 sb.append(m); 58 } 59 message = sb.toString(); 60 } 61 Log.d(tag, message, t); 62 } 63 } 64 65 } 66