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

Jacinthe ·
更新时间:2024-09-21
· 534 次阅读

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就只会打印你所设置的日志内容了
在这里插入图片描述


作者:大青儿



Android Studio 安卓学习 学习笔记 studio 学习 logcat 教程 Android

需要 登录 后方可回复, 如果你还没有账号请 注册新账号