logcat use

时间:2023-12-31 08:32:26

将已经存在的工程导入到eclipse步骤:

①:首先复制当前工程所在的路径。

②:然后在eclipse,右键->Import->General->Existing Projects into Workspace->将复制的路径黏贴进去->Browser->Copy projects into workspace->finish。

 1 package com.itheima.logcat;
2
3 import android.os.Bundle;
4 import android.app.Activity;
5 import android.util.Log;
6 import android.view.Menu;
7
8 public class MainActivity extends Activity {
9
10 private static final String tag = "MainActivity";
11
12 @Override
13 protected void onCreate(Bundle savedInstanceState) {
14 super.onCreate(savedInstanceState);
15 setContentView(R.layout.activity_main);
16
17 Log.v(tag, "我是v级别"); 对应的是蓝色
18 Log.i(tag, "我是i级别"); 绿色
19 Log.d(tag, "我是d级别"); 黑色
20 Log.w(tag, "我是w级别"); 黄色
21 Log.e(tag, "我是e级别"); 红色
22 }
23
24 @Override
25 public boolean onCreateOptionsMenu(Menu menu) {
26 // Inflate the menu; this adds items to the action bar if it is present.
27 getMenuInflater().inflate(R.menu.main, menu);
28 return true;
29 }
30
31 }

解读 1 Log.v(tag, "我是v级别");

tag Used to identify the source of a log message. It usually identifies the class or activity where the log call occurs.(用于标识日志消息的源。它通常标识日志调用发生的类或活动。)

msg The message you would like logged.(您希望记录的消息。)

如何快速的过滤出我自己打印的日志信息呢?

可以通过左边的Filters过滤器。 通过Tag来过滤。