替换引入项目的日志

编程入门 行业动态 更新时间:2024-10-13 02:19:17

替换引入<a href=https://www.elefans.com/category/jswz/34/1771421.html style=项目的日志"/>

替换引入项目的日志


import java.io.IOException;/*** 全局替换//import android.util.Log;* Created by efan on 2017/4/13.*/public class XLog {/** 总开关 */public final static boolean SWITCH = true;/*** 启用默认tag(自定义tag实效)*/public final static boolean IS_ENABLE_DEF_TAG = true;private final static String DEFT_AG = "调试信息";private static int stepNumber = 0;private static int MaxLength = 1024 * 3;private final static boolean V = SWITCH && true;private final static boolean D = SWITCH && true;private final static boolean I = SWITCH && true;private final static boolean W = SWITCH && true;private final static boolean E = SWITCH && true;public static void v(String tag, String msg) {if (V) {if (msg.length() > MaxLength) {for (int i = 0; i < msg.length() / MaxLength; i++) {if (msg.length() > MaxLength) {android.util.Log.v(IS_ENABLE_DEF_TAG ? DEFT_AG : tag, getScope() + "  " + msg.substring(0, MaxLength));msg = msg.substring(MaxLength);}}}android.util.Log.v(IS_ENABLE_DEF_TAG ? DEFT_AG : tag, getScope() + "  " + msg);}}public static void d(String tag, String msg) {if (D) {android.util.Log.d(IS_ENABLE_DEF_TAG ? DEFT_AG : tag, getScope() + "  " + msg);}}public static void d(String tag, String msg, Object... args) {if (D) {android.util.Log.d(IS_ENABLE_DEF_TAG ? DEFT_AG : tag, String.format(msg, args));}}public static void i(String tag, String msg) {if (I) {android.util.Log.i(IS_ENABLE_DEF_TAG ? DEFT_AG : tag, getScope() + "  " + msg);}}public static void w(String tag, String msg) {if (W) {android.util.Log.w(IS_ENABLE_DEF_TAG ? DEFT_AG : tag, getScope() + "  " + msg);}}public static void e(String tag, String msg) {if (E) {android.util.Log.e(IS_ENABLE_DEF_TAG ? DEFT_AG : tag, getScope() + "  " + msg);}}public static void v(String msg) {if (V) {android.util.Log.v(DEFT_AG + ":", getScope() + "  " + msg);}}public static void d(String msg) {if (D) {android.util.Log.d(DEFT_AG + ":", getScope() + "  " + msg);}}public static void i(String msg) {if (I) {android.util.Log.i(DEFT_AG + ":", getScope() + "  " + msg);}}public static void w(String msg) {if (W) {android.util.Log.w(DEFT_AG + ":", getScope() + "  " + msg);}}public static void e(String msg) {if (E) {android.util.Log.e(DEFT_AG + ":", getScope() + "  " + msg);}}/*** 打印异常详细信息,推荐使用** @param e e*/public static void e(Exception e) {if (E) {android.util.Log.e(DEFT_AG + ":", getScope() + "  " + "", e);}}/*** 打印异常详细信息,推荐使用** @param e e*/public static void e(Throwable e) {if (E) {android.util.Log.e(DEFT_AG + ":", getScope() + "  " + "", e);}}/*** 打印异常详细信息,推荐使用** @param e e*/public static void printExceptionInfo(Exception e) {if (E) {android.util.Log.e(DEFT_AG + ":", getScope() + "  " + "", e);}}private static final int DEFAULT_STACK_TRACE_LINE_COUNT = 4;private static String getScope() {StackTraceElement trace = Thread.currentThread().getStackTrace()[4];return "(" + trace.getFileName() + ":" + trace.getLineNumber() + ")" + "#" + trace.getMethodName() + "    ";//        Thread.currentThread().getStackTrace()[4].toString().substring(23).replaceFirst("\\.", "#");// StackTraceElement trace = Thread.currentThread().getStackTrace()[DEFAULT_STACK_TRACE_LINE_COUNT];// android.util.Log.i(DEFT_AG, trace.getClassName());// String stackTraceMsgArr = trace.toString();// return stackTraceMsgArr.substring(stackTraceMsgArr.indexOf("(")) + "#" + trace.getMethodName();}/*** 调用处子类方法所在位置** @param msg smg*/public static void getChildLog(String msg) {if (V) {StackTraceElement stackTraceElement = Thread.currentThread().getStackTrace()[4];String stackTraceMsgArr = stackTraceElement.toString();android.util.Log.i(DEFT_AG, stackTraceMsgArr.substring(stackTraceMsgArr.indexOf("(")) + "#" + stackTraceElement.getMethodName() + " msg:" + msg);}}/** 打印步骤 */public static void showStepLogInfo() {if (V) {android.util.Log.v("步骤" + ":", getScope() + "  " + "" + stepNumber++);}}public static String getStackTraceString(Exception e) {return android.util.Log.getStackTraceString(e);}public static void e(String tag, String s, Exception ex) {if (E) {android.util.Log.e(IS_ENABLE_DEF_TAG ? DEFT_AG : tag, getScope() + "  " + s, ex);}}public static void e(String tag, String msg, Throwable e, Object... args) {if (E) {android.util.Log.e(IS_ENABLE_DEF_TAG ? DEFT_AG : tag, String.format(msg, args), e);}}}

 

更多推荐

替换引入项目的日志

本文发布于:2024-02-08 21:11:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1675094.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:项目   日志

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!