Package com. rctd. tmzs. util;
Import android. util. Log;
/**
* Log output Tool
* @ Author WuHao; Email: 1024778537@qq.com
* @ Version V1.0; Date: 11:35:20
*/
Public class LogUtil {
Private static String tag = "LogUtil ";
Private int logLevel = Log. VERBOSE;
Private static final boolean isDebug = true;
Private static LogUtil instance = null;
Public static synchronized LogUtil getInstance (){
Return getInstance (Log. VERBOSE );
}
Public static synchronized LogUtil getInstance (int level ){
If (instance = null)
Instance = new LogUtil ();
If (level> = 2)
Instance. setLevel (level );
Return instance;
}
Private LogUtil (){
}
Public void setLevel (int level ){
This. logLevel = level;
}
Private String getFunctionName (){
StackTraceElement [] sts = Thread. currentThread (). getStackTrace ();
If (sts = null ){
Return null;
}
For (StackTraceElement st: sts ){
If (st. isNativeMethod ()){
Continue;
}
If (st. getClassName (). equals (Thread. class. getName ())){
Continue;
}
If (st. getClassName (). equals (this. getClass (). getName ())){
Continue;
}
Return "[" + Thread. currentThread (). getName () + "(" + Thread. currentThread (). getId () + "):" + st. getFileName () + ":" + st. getLineNumber () + "]";
}
Return null;
}
Private void outMsg (Object str ){
String msg = (str = null? "": Str. toString ());
String name = getFunctionName ();
String ls = (name = null? Msg. toString (): (name + "-" + msg ));
If (logLevel = Log. DEBUG ){
Log. d (tag, ls );
} Else if (logLevel = Log. INFO ){
Log. I (tag, ls );
} Else if (logLevel = Log. WARN ){
Log. w (tag, ls );
} Else if (logLevel = Log. ERROR ){
Log. e (tag, ls );
} Else {
Log. v (tag, ls );
}
}
Public void out (Object msg ){
If (isDebug ){
OutMsg (msg );
}
}
}