//package com.airplane.app.utils;
/*
* Copyright (C) 2009 China Mobile Research Institute
*
* 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.
*/
import java.util.Hashtable;
import android.util.Config;
import android.util.Log;
/**
* Utility log tool.
*
* @author MengZhao
*/
public class MyLogger {
private static boolean sIsLoggerEnable = Config.DEBUG;
private final static String LOG_TAG = "[SaveDataFlow]";
private static Hashtable sLoggerTable;
static {
sLoggerTable = new Hashtable();
if (Config.DEBUG)
sIsLoggerEnable = true;
else
sIsLoggerEnable = false;
}
private String mClassName;
public static MyLogger getLogger(String className) {
MyLogger classLogger = (MyLogger) sLoggerTable.get(className);
if (classLogger == null) {
classLogger = new MyLogger(className);
sLoggerTable.put(className, classLogger);
}
return classLogger;
}
private MyLogger(String name) {
mClassName = name;
}
public void v(String log) {
if (sIsLoggerEnable) {
Log.v(LOG_TAG, "{Thread:" + Thread.currentThread().getName() + "}" + "[" + mClassName + ":] " + log);
}
}
public void d(String log) {
if (sIsLoggerEnable) {
Log.d(LOG_TAG, "{Thread:" + Thread.currentThread().getName() + "}" + "[" + mClassName + ":] " + log);
}
}
public void i(String log) {
if (sIsLoggerEnable) {
Log.i(LOG_TAG, "{Thread:" + Thread.currentThread().getName() + "}" + "[" + mClassName + ":] " + log);
}
}
public void i(String log, Throwable tr) {
if (sIsLoggerEnable) {
Log.i(LOG_TAG, "{Thread:" + Thread.currentThread().getName() + "}" + "[" + mClassName + ":] " + log + "\n" + Log.getStackTraceString(tr));
}
}
public void w(String log) {
if (sIsLoggerEnable) {
Log.w(LOG_TAG, "{Thread:" + Thread.currentThread().getName() + "}" + "[" + mClassName + ":] " + log);
}
}
public void w(String log, Throwable tr) {
if (sIsLoggerEnable) {
Log.w(LOG_TAG, "{Thread:" + Thread.currentThread().getName() + "}" + "[" + mClassName + ":] " + log + "\n" + Log.getStackTraceString(tr));
}
}
public void e(String log) {
Log.e(LOG_TAG, "{Thread:" + Thread.currentThread().getName() + "}" + "[" + mClassName + ":] " + log);
}
public void e(String log, Throwable tr) {
Log.e(LOG_TAG, "{Thread:" + Thread.currentThread().getName() + "}" + "[" + mClassName + ":] " + log + "\n" + Log.getStackTraceString(tr));
}
}