Android logcat系统

一 .logcat命令介绍

android log系统:

logcat介绍 :

logcat是android中的一个命令行工具,可以用于得到程序的log信息.

二.C/C++logcat访问接口

Android系统中的C/C++日志接口是通过宏来使用的。在system/core/include/android/log.h定义了日志的级别:

/*
 * Android log priority values, in ascending priority order.
 */
typedef enum android_LogPriority {
	ANDROID_LOG_UNKNOWN = 0,
	ANDROID_LOG_DEFAULT,	/* only for SetMinPriority() */
	ANDROID_LOG_VERBOSE,
	ANDROID_LOG_DEBUG,
	ANDROID_LOG_INFO,
	ANDROID_LOG_WARN,
	ANDROID_LOG_ERROR,
	ANDROID_LOG_FATAL,
	ANDROID_LOG_SILENT,	/* only for SetMinPriority(); must be last */
} android_LogPriority;

在system/core/include/cutils/log.h中,定义了对应的宏,如对应于ANDROID_LOG_VERBOSE的宏LOGV:

/*
 * This is the local tag used for the following simplified
 * logging macros. You can change this preprocessor definition
 * before using the other macros to change the tag.
 */
#ifndef LOG_TAG
#define LOG_TAG NULL
#endif
 
/*
 * Simplified macro to send a verbose log message using the current LOG_TAG.
 */
#ifndef LOGV
#if LOG_NDEBUG
#define LOGV(...)   ((void)0)
#else
#define LOGV(...)   ((void)LOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
#endif
#endif
 
/*
 * Basic log message macro.
 *
 * Example:
 *  LOG(LOG_WARN, NULL, "Failed with error %d", errno);
 *
 * The second argument may be NULL or "" to indicate the "global" tag.
 */
#ifndef LOG
#define LOG(priority, tag, ...) \
     LOG_PRI(ANDROID_##priority, tag, __VA_ARGS__)
#endif
 
/*
 * Log macro that allows you to specify a number for priority.
 */
#ifndef LOG_PRI
#define LOG_PRI(priority, tag, ...) \
     android_printLog(priority, tag, __VA_ARGS__)
#endif
 
/*
 * ================================================================
 *
 * The stuff in the rest of this file should not be used directly.
 */
#define android_printLog(prio, tag, fmt...) \
     __android_log_print(prio, tag, fmt)

  因此,如果要使用C/C++日志接口,只要定义自己的LOG_TAG宏和包含头文件system/core/include/cutils/log.h就可以了:

 #define LOG_TAG "MY LOG TAG"

         #include <cutils/log.h>

         就可以了,例如使用LOGV:

         LOGV("This is the log printed by LOGV in android user space.");

三.Java logcat访问接口

Android系统在Frameworks层中定义了Log接口(frameworks/base/core/java/android/util/Log.java):

................................................
 
public final class 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;
 
.....................................................
 
	public static int v(String tag, String msg) {
		return println_native(LOG_ID_MAIN, VERBOSE, tag, msg);
	}
 
	public static int v(String tag, String msg, Throwable tr) {
		return println_native(LOG_ID_MAIN, VERBOSE, tag, msg + '\n' + getStackTraceString(tr));
	}
 
	public static int d(String tag, String msg) {
		return println_native(LOG_ID_MAIN, DEBUG, tag, msg);
	}
 
	public static int d(String tag, String msg, Throwable tr) {
		return println_native(LOG_ID_MAIN, DEBUG, tag, msg + '\n' + getStackTraceString(tr));
	}
 
	public static int i(String tag, String msg) {
		return println_native(LOG_ID_MAIN, INFO, tag, msg);
	}
 
	public static int i(String tag, String msg, Throwable tr) {
		return println_native(LOG_ID_MAIN, INFO, tag, msg + '\n' + getStackTraceString(tr));
	}
 
	public static int w(String tag, String msg) {
		return println_native(LOG_ID_MAIN, WARN, tag, msg);
	}
 
	public static int w(String tag, String msg, Throwable tr) {
		return println_native(LOG_ID_MAIN, WARN, tag, msg + '\n' + getStackTraceString(tr));
	}
 
	public static int w(String tag, Throwable tr) {
		return println_native(LOG_ID_MAIN, WARN, tag, getStackTraceString(tr));
	}
	
	public static int e(String tag, String msg) {
		return println_native(LOG_ID_MAIN, ERROR, tag, msg);
	}
 
	public static int e(String tag, String msg, Throwable tr) {
		return println_native(LOG_ID_MAIN, ERROR, tag, msg + '\n' + getStackTraceString(tr));
	}
 
..................................................................
 
	/**@hide */ public static native int println_native(int bufID,
		int priority, String tag, String msg);
}

因此,如果要使用Java日志接口,只要在类中定义的LOG_TAG常量和引用android.util.Log就可以了:

        private static final String LOG_TAG = "MY_LOG_TAG";

        Log.i(LOG_TAG, "This is the log printed by Log.i in android user space.");

四.logcat命令参数

参数

描述

-b <buffer>加载一个可使用的日志缓冲区供查看,比如event和radio。默认值是main
-c清除缓冲区中的全部日志并退出(清除完后可以使用-g查看缓冲区)
-d将缓冲区的log转存到屏幕中然后退出
-f <filename>将log输出到指定的文件中<文件名>.默认为标准输出(stdout)
-g打印日志缓冲区的大小并退出
-n <count>设置日志的最大数目<count>,默认值是4,需要和-r选项一起使用
-r <kbytes>没<kbytes>时输出日志,默认值是16,需要和-f选项一起使用
-s设置过滤器
-v <format>设置输出格式的日志消息。默认是短暂的格式。支持的格式列表
//将缓冲区的log打印到屏幕并退出

adb logcat -d

//清除缓冲区log(testCase运行前可以先清除一下)

adb logcat -c

//打印缓冲区大小并退出

adb logcat -g

//输出log

adb logcat -f /data/local/tmp/log.txt -n 10 -r 1

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/429946.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

opencart3 添加速卖通商品脚本

非爬虫&#xff0c;只能把速卖通商品信息拿下来解析插入到自己的项目里。 刚接触opencart3没多久&#xff0c;有一些新项目需要添加商品&#xff0c;每次手动从速卖通复制信息又很慢&#xff0c;就自己写了一个脚本。 思路&#xff1a;速卖通商品详情页有一段数据包含了几乎所…

Vue-02

开发者工具 安装插件&#xff0c;用于调试 Vue 应用。 https://chrome.zzzmh.cn/index 搜索 Vue &#xff0c;下载 Vue.js Devtools &#xff0c;此插件可以帮助更新信息&#xff0c;而不通过控制台更新&#xff0c;更方便调试。 注&#xff1a;安装插件后&#xff0c;记得在插…

Hello World!第一个labview程序

软件版本&#xff1a; labview myrio 2021英文版 因为没有找到中文版的&#xff0c;据说是myrio没有中文版本 实验内容&#xff1a; 文本显示&#xff0c;程序界面输入任意文本&#xff0c;然后运行程序 在前面板显示出输入的文本 以下为具体步骤&#xff1a; 第一步&…

no declaration can be found for element ‘rabbit:connection-factory‘

spring-mvc 配置 rabbitmq 出现问题。 我的解决方案如下&#xff1a; 1 找到配置文件 spring-rabbitmq.xml 我的配置文件叫&#xff1a;spring-rabbitmq.xml&#xff0c;你们按照自己的查找。 2 定位如下URI 接着 Ctrl鼠标左键 3 确定spring-rabbit-x.x.xsd 按照步骤2 &…

拿到年终奖马上离职,厚道吗?

拿到年终奖马上离职&#xff0c;厚道吗&#xff1f; 大家好&#xff0c;我是銘&#xff0c;全栈开发程序员。 今天在知乎上看到一个问题&#xff1a;拿到年终奖后马上辞职&#xff0c;厚道吗&#xff1f; image-20240229232132786 我的答案是&#xff1a;厚道&#xff0c;非常厚…

day03_Vue_Element

文章目录 01.Ajax1.1 Ajax 概述1.2 同步异步1.3 原生Ajax 2. Axios2.1 Axios的基本使用2.2 Axios快速入门2.3请求方法的别名2.4 案例 3 前后台分离开发3.1 前后台分离开发介绍 04 YAPI4.1 YAPI介绍4.2 接口文档管理 05 前端工程化5.1 前端工程化介绍5.2 前端工程化入门5.2.1 环…

吴恩达机器学习全课程笔记第七篇

目录 前言 P114-P120 推荐系统 协同过滤 均值归一化 协同过滤的tensorflow实现 查找相关项目 P121-P130 基于内容的过滤 强化学习 P131-P142 状态动作值函数定义 Bellman方程 随机环境 连续状态空间应用实例 前言 这是吴恩达机器学习笔记的第七篇&#xff0c;…

【C++】list模拟实现+反向迭代器

list模拟实现 list定义list用法list iterator的使用begin() end()rbegin()rend() reverse()sort()merge()unique()remove()splice() list模拟实现struct和class的区别list三个类模板默认成员函数构造函数拷贝构造函数赋值运算符重载析构函数 数据修改操作push_back()push_fron…

阿里云2核4G服务器支持多少人在线?多少钱?

阿里云2核4G服务器多少钱一年&#xff1f;2核4G5M带宽优惠价格199元一年&#xff0c;轻量应用服务器2核4G4M带宽165元一年&#xff0c;2核4G服务器30元3个月&#xff0c;可以在阿里云官方活动查看2核4G配置详细报价 https://t.aliyun.com/U/bLynLC 阿里云2核4G服务器价格 2核4G…

java 版本企业招标投标管理系统源码+功能描述+tbms+及时准确+全程电子化

功能描述 1、门户管理&#xff1a;所有用户可在门户页面查看所有的公告信息及相关的通知信息。主要板块包含&#xff1a;招标公告、非招标公告、系统通知、政策法规。 2、立项管理&#xff1a;企业用户可对需要采购的项目进行立项申请&#xff0c;并提交审批&#xff0c;查看所…

cannot import name ‘Flask‘ from partially initialized module ‘flask‘

bug&#xff1a; ImportError: cannot import name Flask from partially initialized module flask (most likely due to a circular import) (G:\pythonProject6\flask.py) 这个是因为包的名字和文件的名字一样 修改文件名&#xff1a; 结果 &#x1f923;&#x1f923;&…

【QT】Qt Charts概述

目录 1 QtCharts模块 2 图表的主要组成部分 2.1 QChartView的功能 2.2 序列 2.3 坐标轴 2.4 图例 3 一个简单的QChart绘图程序 QtCharts是Qt提供的图表模块&#xff0c;在Qt5.7以前只有商业版才有Qt Charts&#xff0c;但是从Qt5.7开始&#xff0c;社区版本也包含了Qt C…

基于SpringBoot+Apache POI的前后端分离外卖项目-苍穹外卖(十九)

数据导出 1. 工作台1.1 需求分析和设计1.1.1 产品原型1.1.2 接口设计1.2.1 Controller层1.2.2 Service层接口1.2.3 Service层实现类1.2.4 Mapper层 1.3 功能测试 2. Apache POI2.1 介绍2.2 入门案例2.2.1 将数据写入Excel文件2.2.2 读取Excel文件中的数据 3. 导出运营数据Excel…

重学SpringBoot3-yaml文件配置

重学SpringBoot3-yaml文件配置 引言YAML 基本语法YAML 数据类型YAML 对象YAML 数组复合结构标量引用 YAML 文件结构Spring Boot 中的 YAML 配置注意事项总结参考 引言 YAML&#xff08;YAML Ain’t Markup Language&#xff09;是一种常用于配置文件的数据序列化格式&#xff…

LabVIEW起重机工作参数远程监测系统

LabVIEW起重机工作参数远程监测系统 随着起重机技术的持续发展&#xff0c;对其工作参数的实时监控需求日益增加。设计了一个基于LabVIEW和TBox的起重机工作参数远程监测系统&#xff0c;能够实现起重机工作参数的实时采集、传输、解析和显示&#xff0c;有效提升起重机的性能…

【Linux-shell系列】多脚本同时启动

&#x1f49d;&#x1f49d;&#x1f49d;欢迎来到我的博客&#xff0c;很高兴能够在这里和您见面&#xff01;希望您在这里可以感受到一份轻松愉快的氛围&#xff0c;不仅可以获得有趣的内容和知识&#xff0c;也可以畅所欲言、分享您的想法和见解。 推荐:kwan 的首页,持续学…

基于51单片机风速仪风速测量台风预警数码管显示

基于51单片机风速仪风速测量报警数码管显示 1. 主要功能&#xff1a;2. 讲解视频&#xff1a;3. 仿真4. 程序代码5. 设计报告6. 设计资料内容清单&&下载链接资料下载链接&#xff1a; 基于51单片机风速仪风速测量报警数码管显示( proteus仿真程序设计报告讲解视频&…

Elasticsearch:使用 Streamlit、语义搜索和命名实体提取开发 Elastic Search 应用程序

作者&#xff1a;Camille Corti-Georgiou 介绍 一切都是一个搜索问题。 我在 Elastic 工作的第一周就听到有人说过这句话&#xff0c;从那时起&#xff0c;这句话就永久地印在了我的脑海中。 这篇博客的目的并不是我出色的同事对我所做的相关陈述进行分析&#xff0c;但我首先…

第 5 章 ROS常用组件坐标msg消息(自学二刷笔记)

重要参考&#xff1a; 课程链接:https://www.bilibili.com/video/BV1Ci4y1L7ZZ 讲义链接:Introduction Autolabor-ROS机器人入门课程《ROS理论与实践》零基础教程 在ROS中内置一些比较实用的工具&#xff0c;通过这些工具可以方便快捷的实现某个功能或调试程序&#xff0c;从…

仿牛客网项目---关注模块的实现

本篇文章是关于我的项目的关注模块的开发。 关注模块的开发实现了用户之间的关注功能和关注列表的展示。通过使用相应的服务类处理关注和取消关注操作&#xff0c;并利用用户服务类获取用户信息&#xff0c;实现了关注功能的存储和查询。同时&#xff0c;通过触发关注事件&…
最新文章