Home | History | Annotate | Download | only in deskclock
      1 /*
      2  * Copyright (C) 2008 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 /**
     18  * package-level logging flag
     19  */
     20 
     21 package com.android.deskclock;
     22 
     23 import android.os.Build;
     24 import android.util.Log;
     25 
     26 public class LogUtils {
     27 
     28     public final static String LOGTAG = "AlarmClock";
     29     public final static boolean DEBUG = "eng".equals(Build.TYPE) || "userdebug".equals(Build.TYPE);
     30 
     31     public static void v(String message, Object... args) {
     32         if (DEBUG || Log.isLoggable(LOGTAG, Log.VERBOSE)) {
     33             Log.v(LOGTAG, args == null || args.length == 0
     34                     ? message : String.format(message, args));
     35         }
     36     }
     37 
     38     public static void v(String tag, String message, Object... args) {
     39         if (DEBUG || Log.isLoggable(LOGTAG, Log.VERBOSE)) {
     40             Log.v(LOGTAG + "/" + tag, args == null || args.length == 0 ? message
     41                     : String.format(message, args));
     42         }
     43     }
     44 
     45     public static void d(String message, Object... args) {
     46         if (DEBUG || Log.isLoggable(LOGTAG, Log.DEBUG)) {
     47             Log.d(LOGTAG, args == null || args.length == 0 ? message
     48                     : String.format(message, args));
     49         }
     50     }
     51 
     52     public static void d(String tag, String message, Object... args) {
     53         if (DEBUG || Log.isLoggable(LOGTAG, Log.DEBUG)) {
     54             Log.d(LOGTAG + "/" + tag, args == null || args.length == 0 ? message
     55                     : String.format(message, args));
     56         }
     57     }
     58 
     59     public static void i(String message, Object... args) {
     60         if (DEBUG || Log.isLoggable(LOGTAG, Log.INFO)) {
     61             Log.i(LOGTAG, args == null || args.length == 0 ? message
     62                     : String.format(message, args));
     63         }
     64     }
     65 
     66     public static void i(String tag, String message, Object... args) {
     67         if (DEBUG || Log.isLoggable(LOGTAG, Log.INFO)) {
     68             Log.i(LOGTAG + "/" + tag, args == null || args.length == 0 ? message
     69                     : String.format(message, args));
     70         }
     71     }
     72 
     73     public static void w(String message, Object... args) {
     74         if (DEBUG || Log.isLoggable(LOGTAG, Log.WARN)) {
     75             Log.w(LOGTAG, args == null || args.length == 0 ? message
     76                     : String.format(message, args));
     77         }
     78     }
     79 
     80     public static void w(String tag, String message, Object... args) {
     81         if (DEBUG || Log.isLoggable(LOGTAG, Log.WARN)) {
     82             Log.w(LOGTAG + "/" + tag, args == null || args.length == 0 ? message
     83                     : String.format(message, args));
     84         }
     85     }
     86 
     87     public static void e(String message, Object... args) {
     88         if (DEBUG || Log.isLoggable(LOGTAG, Log.ERROR)) {
     89             Log.e(LOGTAG, args == null || args.length == 0 ? message
     90                     : String.format(message, args));
     91         }
     92     }
     93 
     94     public static void e(String tag, String message, Object... args) {
     95         if (DEBUG || Log.isLoggable(LOGTAG, Log.ERROR)) {
     96             Log.e(LOGTAG + "/" + tag, args == null || args.length == 0 ? message
     97                     : String.format(message, args));
     98         }
     99     }
    100 
    101     public static void e(String message, Exception e) {
    102         if (DEBUG || Log.isLoggable(LOGTAG, Log.ERROR)) {
    103             Log.e(LOGTAG, message, e);
    104         }
    105     }
    106 
    107     public static void e(String tag, String message, Exception e) {
    108         if (DEBUG || Log.isLoggable(LOGTAG, Log.ERROR)) {
    109             Log.e(LOGTAG + "/" + tag, message, e);
    110         }
    111     }
    112 
    113     public static void wtf(String message, Object... args) {
    114         if (DEBUG || Log.isLoggable(LOGTAG, Log.ASSERT)) {
    115             Log.wtf(LOGTAG, args == null || args.length == 0 ? message
    116                     : String.format(message, args));
    117         }
    118     }
    119 
    120     public static void wtf(String tag, String message, Object... args) {
    121         if (DEBUG || Log.isLoggable(LOGTAG, Log.ASSERT)) {
    122             Log.wtf(LOGTAG + "/" + tag, args == null || args.length == 0 ? message
    123                     : String.format(message, args));
    124         }
    125     }
    126 }
    127