android 常用工具类LogUtils

刚刚的重新排版一下

/**

  • Created by sakura on 2016/9/29.
    /
    public class LogUtils {
    protected static final String TAG = "-----sakura---";
    /
    *

    • Send a VERBOSE log message.
    • @param msg
    •        The message you would like logged.
      

    */
    public static void v(String msg) {
    if (BuildConfig.DEBUG)
    Log.v(TAG, msg);
    }
    public static void v(String msg, Throwable thr) {
    if (BuildConfig.DEBUG)
    Log.v(TAG, buildMessage(msg), thr);
    }

    /**

    • @param tag -->标记
    • @param msg -->内容
      /
      public static void v(String tag,String msg){
      if (BuildConfig.DEBUG){
      Log.v(TAG, msg);
      }
      }
      /
      *
    • Send a DEBUG log message.
    • @param msg
      */
      public static void d(String msg) {
      if (BuildConfig.DEBUG)
      Log.d(TAG, buildMessage(msg));
      }

    /**

    • Send a DEBUG log message and log the exception.
    • @param msg
    •        The message you would like logged.
      
    • @param thr
    •        An exception to log
      

    */
    public static void d(String msg, Throwable thr) {
    if (BuildConfig.DEBUG)
    Log.d(TAG, buildMessage(msg), thr);
    }

    public static void d(String tag,String msg){
    if (BuildConfig.DEBUG){
    Log.d(tag,"===" + msg);
    }
    }

    /**

    • Send an INFO log message.
    • @param msg
    •        The message you would like logged.
      

    */
    public static void i(String msg) {
    if (BuildConfig.DEBUG)
    Log.i(TAG, buildMessage(msg));
    }

    /**

    • Send a INFO log message and log the exception.
    • @param msg
    •        The message you would like logged.
      
    • @param thr
    •        An exception to log
      

    */
    public static void i(String msg, Throwable thr) {
    if (BuildConfig.DEBUG)
    Log.i(TAG, buildMessage(msg), thr);
    }

    public static void i(String tag,String msg){
    if (BuildConfig.DEBUG){
    Log.i(TAG+tag,"===" + msg);
    }
    }

    /**

    • Send an ERROR log message.
    • @param msg
    •        The message you would like logged.
      

    */
    public static void e(String msg) {
    if (BuildConfig.DEBUG)
    Log.e(TAG, buildMessage(msg));
    }

    /**

    • Send a WARN log message
    • @param msg
    •        The message you would like logged.
      

    */
    public static void w(String msg) {
    if (BuildConfig.DEBUG)
    Log.w(TAG, buildMessage(msg));
    }

    /**

    • Send a WARN log message and log the exception.
    • @param msg
    •        The message you would like logged.
      
    • @param thr
    •        An exception to log
      

    */
    public static void w(String msg, Throwable thr) {
    if (BuildConfig.DEBUG)
    Log.w(TAG, buildMessage(msg), thr);
    }

    /**

    • Send an empty WARN log message and log the exception.
    • @param thr
    •        An exception to log
      

    */
    public static void w(Throwable thr) {
    if (BuildConfig.DEBUG)
    Log.w(TAG, buildMessage(""), thr);
    }

    /**

    • Send an ERROR log message and log the exception.
    • @param msg
    •        The message you would like logged.
      
    • @param thr
    •        An exception to log
      

    */
    public static void e(String msg, Throwable thr) {
    if (BuildConfig.DEBUG)
    Log.e(TAG, buildMessage(msg), thr);
    }

    /**

    • Building Message
    • @param msg
    •        The message you would like logged.
      
    • @return Message String
      */
      protected static String buildMessage(String msg) {
      StackTraceElement caller = new Throwable().fillInStackTrace().getStackTrace()[2];
      return new StringBuilder().append(caller.getClassName()).append(".").append(caller.getMethodName()).append("(): ").append(msg).toString();
      }

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 主要积累一些开发中比较 常用的工具类,部分借鉴于网络,主要来源于平时开发因需求而生的小工具类 13、ArithUt...
    大鸭梨leepear阅读 3,909评论 0 1
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,473评论 19 139
  • <?php /** * 常用函数库 * */ class Core_Fun { /** * 对变量进行反...
    寻梦xunm阅读 3,471评论 0 0
  • 今天的代码折腾了好久,出差中手机就是不方便呐。昨天是对文件对象进行只读操作,今天开始对文件进行写入操作。...
    sinkpink阅读 2,187评论 1 0
  • 一、基础素养指标存在的问题? 1.英语口语及科学实验存在较大差距,尤其是科学实验需进一步提升。 2.基...
    姚久亮阅读 3,304评论 0 0