当前位置: 首页 > news >正文

linux下logcat命令,Android logcat 命令以及 Log机制

Android logcat命令

1. logcat -c 清除已有log信息

2.logcat -b main 显示主缓冲区的log

logcat -b radio 显示无线缓冲区的log

logcat -b events 显示事件缓冲区的log

3.logcat -f [filename] 将log保存到指定的文件中,例如 logcat -b radio -f /data/radio.log

4.logcat -v 设置logcat输出的格式

主要有7种输出格式:

1. brief — Display priority/tag and PID of originating process (the default format).

2. process — Display PID only.

3. tag — Display the priority/tag only.

4. thread — Display process:thread and priority/tag only.

5. raw — Display the raw log message, with no other metadata fields.

6. time — Display the date, invocation time, priority/tag, and PID of the originating process.

7. long — Display all metadata fields and separate messages with a blank lines.

比较常用的是显示时间:logcat -v time &

5.logcat -g 查看缓冲区的大小

logcat -g main

logcat -g radio

logcat -g events

Log机制的一些理解:

1. 系统结构

应用程序调用应用程序框架层的Java接口(android.util.Log)来使用日志系统,这个Java接口通过JNI方法和系统运行库最终调用内核驱动程序Logger把Log写到内核空间中。

2. 关键代码及理解

一. 应用程序框架层日志系统Java接口的实现

代码位置:frameworks/base/core/java/android/util/Log.java文件中,实现日志系统的Java接口:

publicfinalclassLog {

/**

* Priority constant for the println method; use Log.v.

*/

publicstaticfinalintVERBOSE =2;

/**

* Priority constant for the println method; use Log.d.

*/

publicstaticfinalintDEBUG =3;

/**

* Priority constant for the println method; use Log.i.

*/

publicstaticfinalintINFO =4;

/**

* Priority constant for the println method; use Log.w.

*/

publicstaticfinalintWARN =5;

/**

* Priority constant for the println method; use Log.e.

*/

publicstaticfinalintERROR =6;

/**

* Priority constant for the println method.

*/

publicstaticfinalintASSERT =7;

........................

publicstaticintv(String tag, String msg) {

returnprintln_native(LOG_ID_MAIN, VERBOSE, tag, msg);

}

publicstaticintd(String tag, String msg) {

returnprintln_native(LOG_ID_MAIN, DEBUG, tag, msg);

}

publicstaticinti(String tag, String msg) {

returnprintln_native(LOG_ID_MAIN, INFO, tag, msg);

}

publicstaticintw(String tag, String msg) {

returnprintln_native(LOG_ID_MAIN, WARN, tag, msg);

}

publicstaticinte(String tag, String msg) {

returnprintln_native(LOG_ID_MAIN, ERROR, tag, msg);

}

publicstaticintprintln(intpriority, String tag, String msg) {

returnprintln_native(LOG_ID_MAIN, priority, tag, msg);

}

...................

/** @hide */publicstaticfinalintLOG_ID_MAIN =0;

/** @hide */publicstaticfinalintLOG_ID_RADIO =1;

/** @hide */publicstaticfinalintLOG_ID_EVENTS =2;

/** @hide */publicstaticfinalintLOG_ID_SYSTEM =3;

/** @hide */publicstaticnativeintprintln_native(intbufID,

intpriority, String tag, String msg);

}其中VERBOSE ,DEBUG, INFO,WARN,ERROR,ASSERT代表Log优先级,分别由对应的v,d,i,w,e,a方法实现写入。

在logcat中用

logcat  ActivityManager:w

命令显示ActivityManager标签中等于或高于WARN级别的Log

其中

LOG_ID_MAIN =0LOG_ID_RADIO =1LOG_ID_EVENTS =2LOG_ID_SYSTEM =3;为日志缓冲区,在底层定义了3个设备文件分别为:/dev/log/main、/dev/log/events和/dev/log/radio(),第4个日志缓冲区LOG_ID_SYSTEM并没有对应的设备文件,在这种情况下,它和LOG_ID_MAIN对应同一个缓冲区ID(为什么这样下面会提到)。

在整个Log接口中,最关键的地方声明了println_native本地方法,所有的Log接口都是通过调用这个本地方法来实现Log的注入。下面我们就继续分析这个本地方法println_native。0b1331709591d260c1c78e86d0c51c18.png

http://www.xdnf.cn/news/826309.html

相关文章:

  • 好玩的100个网站收藏
  • BDI和CDI理论四个象限的概念特点及其运用
  • MySQL中information_schema详解
  • Java 匿名内部类
  • R730结构
  • 什么是web service
  • java script 技巧_java script学习方法
  • 如何在VMware Workstation上快速构建一个windows 7虚拟机?[手把手辅导教程]
  • SQL Server中Convert函数转换日期的用法 日期格式化
  • Linux RPM包安装、卸载和升级(rpm命令)
  • python easyicon同类型ico图片批量爬取
  • Linux网络 FTP
  • 揭开pkill的秘密:在Linux中杀死进程的完整指南
  • 图解net use 命令使用示例
  • 安装最新版 MATLAB:详细安装教程
  • viewport详细讲解
  • PaddleNLP系列1-基础知识
  • Java的clientSocket
  • Docker之RUN、COMMAND、ENTRYPOINT辨析
  • Java编程技巧之样板代码
  • 随心听(OnlineMusic)项目 保姆级教程
  • PlayBook 详解
  • SQL语言基础【学习总结】
  • 在Android Studio下进行NDK开发
  • 极狐GitLab 17.1 到底发布了哪些重大功能?
  • 浅谈网络代理 proxy
  • 【物联网】探索NE555:一款经典的集成电路(超详细)
  • JSON 数组
  • 17.Oracle11g的PL/SQL基础
  • 13个程序员常用开发工具用途推荐整理