Android之日志工具

日志工具Log(android.util.Log),共有五个方法打印日志

package android.util;

public final class Log {
    public static final int ASSERT = 7;
    public static final int DEBUG = 3;
    public static final int ERROR = 6;
    public static final int INFO = 4;
    public static final int VERBOSE = 2;
    public static final int WARN = 5;

    Log() {
        throw new RuntimeException("Stub!");
    }

    public static int v(String tag, String msg) {
        throw new RuntimeException("Stub!");
    }

    public static int v(String tag, String msg, Throwable tr) {
        throw new RuntimeException("Stub!");
    }

    public static int d(String tag, String msg) {
        throw new RuntimeException("Stub!");
    }

    public static int d(String tag, String msg, Throwable tr) {
        throw new RuntimeException("Stub!");
    }

    public static int i(String tag, String msg) {
        throw new RuntimeException("Stub!");
    }

    public static int i(String tag, String msg, Throwable tr) {
        throw new RuntimeException("Stub!");
    }

    public static int w(String tag, String msg) {
        throw new RuntimeException("Stub!");
    }

    public static int w(String tag, String msg, Throwable tr) {
        throw new RuntimeException("Stub!");
    }

    public static native boolean isLoggable(String var0, int var1);

    public static int w(String tag, Throwable tr) {
        throw new RuntimeException("Stub!");
    }

    public static int e(String tag, String msg) {
        throw new RuntimeException("Stub!");
    }

    public static int e(String tag, String msg, Throwable tr) {
        throw new RuntimeException("Stub!");
    }

    public static int wtf(String tag, String msg) {
        throw new RuntimeException("Stub!");
    }

    public static int wtf(String tag, Throwable tr) {
        throw new RuntimeException("Stub!");
    }

    public static int wtf(String tag, String msg, Throwable tr) {
        throw new RuntimeException("Stub!");
    }

    public static String getStackTraceString(Throwable tr) {
        throw new RuntimeException("Stub!");
    }

    public static int println(int priority, String tag, String msg) {
        throw new RuntimeException("Stub!");
    }
}

级别从低到高:

  • Log.v() 最为琐碎的,意义最小的日志信息,对应级别verbose
  • Log.d() 打印调试信息,最常用,对应级别debug
  • Log.i() 打印比较重要的数据,可以帮助分析用户行为数据,对应级别info
  • Log.w() 打印警告信息,此处有潜在危险,需要修复,对应级别warn
  • Log.e() 打印程序中的错误信息,,必须修复,对应级别error

注1:tag 参数一般为当前的类名,msg想打印的具体信息

 private String tag = MainActivity.class.getSimpleName();

    /**
    * Activity 被创建时
    */
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        Log.d(tag, "onCreate");
    }

注2:System.out.println(),虽然在eclipse中输入syso,按下代码提示键就会出来,但在Android studio中不支持这种快捷方式。打印日志的的优点:可以添加过滤器、有等级区分、打印可控制、有打印时等。
注3:快捷输入,如输入logd,然后点击tab键,就会补全。
在onCreate()外面输入logt,点击tab,就会以当前的类名作为值生成一个TAG常量

private static final String TAG = "MainActivity";

注4:添加过滤器,选择显示级别,搜索等等

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

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,713评论 19 139
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 175,789评论 25 709
  • Spring Boot 参考指南 介绍 转载自:https://www.gitbook.com/book/qbgb...
    毛宇鹏阅读 47,100评论 6 342
  • linux资料总章2.1 1.0写的不好抱歉 但是2.0已经改了很多 但是错误还是无法避免 以后资料会慢慢更新 大...
    数据革命阅读 14,195评论 2 33
  • 1字面意思:运行循环、跑圈,内部其实就是do-while循环,在这个循环内部不断地处理各种事物,NSRunloop...
    rebeccaBull阅读 1,319评论 0 0