/* * Copyright (c) 2015 [1076559197@qq.com | tchen0707@gmail.com] * * Licensed under the Apache License, Version 2.0 (the "Licenseā€); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.dreamspace.uucampus.common.utils; import android.util.Log; /** * Author: Tau.Chen * Email: 1076559197@qq.com | tauchen1990@gmail.com * Date: 2015/3/10. * Description: Log utils */ public class TLog { /** * This flag to indicate the log is enabled or disabled. */ private static boolean isLogEnable = true; /** * Disable the log output. */ public static void disableLog() { isLogEnable = false; } /** * Enable the log output. */ public static void enableLog() { isLogEnable = true; } /** * Debug * * @param tag * @param msg */ public static void d(String tag, String msg) { if (isLogEnable) { StackTraceElement stackTraceElement = java.lang.Thread.currentThread().getStackTrace()[3]; Log.d(tag, rebuildMsg(stackTraceElement, msg)); } } /** * Information * * @param tag * @param msg */ public static void i(String tag, String msg) { if (isLogEnable) { StackTraceElement stackTraceElement = java.lang.Thread.currentThread().getStackTrace()[3]; Log.i(tag, rebuildMsg(stackTraceElement, msg)); } } /** * Verbose * * @param tag * @param msg */ public static void v(String tag, String msg) { if (isLogEnable) { StackTraceElement stackTraceElement = java.lang.Thread.currentThread().getStackTrace()[3]; Log.v(tag, rebuildMsg(stackTraceElement, msg)); } } /** * Warning * * @param tag * @param msg */ public static void w(String tag, String msg) { if (isLogEnable) { StackTraceElement stackTraceElement = java.lang.Thread.currentThread().getStackTrace()[3]; Log.w(tag, rebuildMsg(stackTraceElement, msg)); } } /** * Error * * @param tag * @param msg */ public static void e(String tag, String msg) { if (isLogEnable) { StackTraceElement stackTraceElement = java.lang.Thread.currentThread().getStackTrace()[3]; Log.e(tag, rebuildMsg(stackTraceElement, msg)); } } /** * Rebuild Log Msg * * @param msg * @return */ private static String rebuildMsg(StackTraceElement stackTraceElement, String msg) { StringBuffer sb = new StringBuffer(); sb.append(stackTraceElement.getFileName()); sb.append(" ("); sb.append(stackTraceElement.getLineNumber()); sb.append(") "); sb.append(stackTraceElement.getMethodName()); sb.append(": "); sb.append(msg); return sb.toString(); } }