安卓学习笔记----Android Studio中日志打印和Logcat简单使用教程

1. 简单介绍:

安卓中打印日志的方法有5中,分别为:
1.Log.v() - VERBOSE
2.Log.d() - DEBUG
3.Log.i()- INFO
4.Log.w()- WARN
5.Log.e()- ERROR

强度从上至下递增

Log部分源码和常量解释:

/**
     * Priority constant for the println method; use Log.v.
     */
    public static final int VERBOSE = 2;

    /**
     * Priority constant for the println method; use Log.d.
     */
    public static final int DEBUG = 3;

    /**
     * Priority constant for the println method; use Log.i.
     */
    public static final int INFO = 4;

    /**
     * Priority constant for the println method; use Log.w.
     */
    public static final int WARN = 5;

    /**
     * Priority constant for the println method; use Log.e.
     */
    public static final int ERROR = 6;

    /**
     * Priority constant for the println method.
     */
    public static final int ASSERT = 7;
2. Logcat简单使用教程

第一步:定义TAG,即日志的标签,建议使用类名+XX的形式,容易找到日志的打印地点,也不会和系统的日志混淆

private static final String TAG = "MainActivityLog";

然后在需要写上日志的地方调用Log方法,举个栗子

Log.d(TAG,"onCreate()方法被调用");

第二步:点击图中框的位置,箭头指向的选项是默认的
在这里插入图片描述
第三步:打开下拉菜单,选择 Edit filter Configuration选项
在这里插入图片描述
第四步:点击+,填写Tag的值,就是刚刚在第一步设置的那个,选择ok
在这里插入图片描述
最后:下拉框选择刚刚自己设置的过滤器,Logcat就只会打印你所设置的日志内容了
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大青儿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值