Created
March 23, 2021 08:31
-
-
Save cesclong/315918cd3f480c07491a014f9d6d5d51 to your computer and use it in GitHub Desktop.
Log类
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Source code recreated from a .class file by IntelliJ IDEA | |
// (powered by Fernflower decompiler) | |
// | |
package com.longzhu.utils.android; | |
import android.text.TextUtils; | |
import android.util.Log; | |
public class PluLog { | |
public static String tagPrefix = "PluLog"; | |
public static boolean debug = true; | |
public static int INDEX = 5; | |
public PluLog() { | |
} | |
public static void d(Object o, int index) { | |
logger("d", o, index); | |
} | |
public static void e(Object o, int index) { | |
logger("e", o, index); | |
} | |
public static void i(Object o, int index) { | |
logger("i", o, index); | |
} | |
public static void w(Object o) { | |
logger("w", o, INDEX); | |
} | |
public static void d(Object o) { | |
logger("d", o, INDEX); | |
} | |
public static void e(Object o) { | |
logger("e", o, INDEX); | |
} | |
public static void i(Object o) { | |
logger("i", o, INDEX); | |
} | |
public static void w(Object o, int index) { | |
logger("w", o, index); | |
} | |
private static void logger(String type, Object o, int index) { | |
if (debug) { | |
String msg = o + ""; | |
String threadName = Thread.currentThread().getName(); | |
String tag = getTag(getCallerStackTraceElement(index)) + ":" + threadName; | |
byte var7 = -1; | |
switch(type.hashCode()) { | |
case 100: | |
if (type.equals("d")) { | |
var7 = 1; | |
} | |
break; | |
case 101: | |
if (type.equals("e")) { | |
var7 = 2; | |
} | |
break; | |
case 105: | |
if (type.equals("i")) { | |
var7 = 0; | |
} | |
break; | |
case 119: | |
if (type.equals("w")) { | |
var7 = 3; | |
} | |
} | |
switch(var7) { | |
case 0: | |
Log.i(tag, msg); | |
break; | |
case 1: | |
Log.d(tag, msg); | |
break; | |
case 2: | |
Log.e(tag, msg); | |
break; | |
case 3: | |
Log.w(tag, msg); | |
} | |
} | |
} | |
private static String getTag(StackTraceElement element) { | |
try { | |
String tag = "%s.%s(Line:%d)"; | |
String callerClazzName = element.getClassName(); | |
callerClazzName = callerClazzName.substring(callerClazzName.lastIndexOf(".") + 1); | |
tag = String.format(tag, callerClazzName, element.getMethodName(), element.getLineNumber()); | |
tag = TextUtils.isEmpty(tagPrefix) ? tag : tagPrefix + ":" + tag; | |
return tag; | |
} catch (Exception var3) { | |
return tagPrefix; | |
} | |
} | |
private static StackTraceElement getCallerStackTraceElement(int index) { | |
if (index >= Thread.currentThread().getStackTrace().length) { | |
index = Thread.currentThread().getStackTrace().length - 1; | |
} | |
return Thread.currentThread().getStackTrace()[index]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment