Android 调试日志Android Debug Log

06/22/2018

本文内容

开发人员用于调试应用程序的一个非常常见的技巧是调用 Console.WriteLine。One very common trick developers use to debug their applications is to make calls to Console.WriteLine. 但是,在移动平台(如 Android)上没有控制台。However, on a mobile platform like Android there is no console. Android 设备会提供日志,可以在编写应用时使用。Android devices provides a log that you can use while writing apps. 这有时称为“logcat” ,原因在于为检索它而输入的命令。This is sometimes referred to as logcat due to the command that you type to retrieve it. 使用“调试日志” 工具,可查看记录的数据。Use the Debug Log tool to view the logged data.

Android 调试日志概述Android Debug Log Overview

“调试日志” 工具使你能够在通过 Visual Studio 调试应用时查看日志输出。The Debug Log tool provides a way to view log output while debugging an app through Visual Studio. 调试日志支持以下设备:The debug log supports the following devices:

物理 Android 手机、平板电脑和可穿戴设备。Physical Android phones, tablets, and wearables.

在 Android Emulator 上运行的 Android 虚拟设备。An Android Virtual device running on the Android Emulator.

备注

“调试日志” 工具并不适用于 Xamarin Live Player。The Debug Log tool does not work with Xamarin Live Player.

“调试日志” 不会显示在设备上独立运行应用时生成的日志消息(即,在从 Visual Studio 断开连接时)。The Debug Log does not display log messages that are generated while the app is running standalone on the device (i.e., while it is disconnected from Visual Studio).

从 Visual Studio 访问调试日志Accessing the Debug Log from Visual Studio

若要打开“设备日志” 工具,单击工具栏上的“设备日志 (logcat)” 图标:To open the Device Log tool, click Device Log (logcat) icon on the toolbar:

或者,也可以从以下菜单选项之一启动“设备日志” 工具:Alternately, launch the Device Log tool from one of the following menu selections:

“视图”>“其他窗口”>“设备日志”View > Other Windows > Device Log

“工具”>“Android”>“设备日志”Tools > Android > Device Log

下面的屏幕截图演示了“调试工具” 窗口的各个部分:The following screenshot illustrates the various parts of the Debug Tool window:

设备选择器 – 选择要监视哪些物理设备或运行的仿真器 。Device Selector – Selects which physical device or running emulator to monitor.

日志条目 – logcat 中的日志消息表。Log Entries – A table of log messages from logcat.

清除日志条目 – 清除表中所有当前日志条目。Clear Log Entries – Clears all current log entries from the table.

播放/暂停 – 在更新或暂停显示新日志条目之间切换 。Play/Pause – Toggles between updating or pausing the display of new log entries.

停止 – 暂停显示新日志条目。Stop – Halts the display of new log entries.

搜索框 – 在此框中输入搜索字符串以筛选日志条目子集 。Search Box – Enter search strings in this box to filter for a subset of log entries.

当显示“调试日志” 工具窗口时,使用设备下拉菜单来选择要监视的 Android 设备:When the Debug Log tool window is displayed, use the device pull-down menu to choose the Android device to monitor:

在选择设备后,“设备日志”工具会从正在运行的应用中自动添加日志条目 – 这些日志条目显示在日志条目表中 。After the device is selected, the Device Log tool automatically adds log entries from a running app – these log entries are shown in the table of log entries. 在设备之间切换将停止和启动设备日志记录。Switching between devices stops and starts device logging. 请注意,在任何设备显示在设备选择器中之前,必须加载 Android 项目。Note that an Android project must be loaded before any devices will appear in the device selector. 如果设备未显示在设备选择器中,请确认它在“启动” 按钮旁边的 Visual Studio 设备下拉列表菜单中可用。If the device does not appear in the device selector, verify that it is available in the Visual Studio device drop-down menu next to the Start button.

要打开“设备日志” ,请单击“视图”>“面板”>“设备日志” :To open the Device Log, click View > Pads > Device Log:

下面的屏幕截图演示了“调试工具” 窗口的各个部分:The following screenshot illustrates the various parts of the Debug Tool window:

设备选择器 – 选择要监视哪些物理设备或运行的仿真器 。Device Selector – Selects which physical device or running emulator to monitor.

日志条目 – logcat 中的日志消息表。Log Entries – A table of log messages from logcat.

清除日志条目 – 清除表中所有当前日志条目。Clear Log Entries – Clears all current log entries from the table.

搜索框 – 在此框中输入搜索字符串以筛选日志条目子集 。Search Box – Enter search strings in this box to filter for a subset of log entries.

显示消息 – 切换显示信息性消息。Show Messages – Toggles the display of informational messages.

显示警告 – 切换显示警告消息(警告消息显示为黄色)。Show Warnings – Toggles the display of warning messages (warning messages are shown in yellow).

显示错误 – 切换显示错误消息(警告消息显示为红色)。Show Errors – Toggles the display of error messages (warning messages are shown in red).

重新连接 – 重新连接到设备并刷新日志条目显示。Reconnect – Reconnects to the device and refreshes the log entry display.

添加标记 – 在最新日志条目后插入标记消息(如 --- Marker N ---),其中 N 是从 1 开始的计数器,并在添加新标记时增加 1 。Add Marker – Inserts a marker message (such as --- Marker N ---) after the latest log entry, where N is a counter that starts from 1 and increments by 1 as new markers are added.

当显示“调试日志”工具窗口时,使用设备下拉菜单来选择要监视的 Android 设备:When the Debug Log tool window is displayed, use the device pull-down menu to choose the Android device to monitor:

在选择设备后,“设备日志”工具会从正在运行的应用中自动添加日志条目 – 这些日志条目显示在日志条目表中 。After the device is selected, the Device Log tool automatically adds log entries from a running app – these log entries are shown in the table of log entries. 在设备之间切换将停止和启动设备日志记录。Switching between devices stops and starts device logging. 请注意,在任何设备显示在设备选择器中之前,必须加载 Android 项目。Note that an Android project must be loaded before any devices will appear in the device selector. 如果设备未显示在设备选择器中,请确认它在“启动” 按钮旁边的 Visual Studio 设备下拉列表菜单中可用。If the device does not appear in the device selector, verify that it is available in the Visual Studio device drop-down menu next to the Start button.

从命令行访问Accessing from the Command Line

另一种方法是通过命令行查看调试日志。Another option is to view the debug log via the command line. 打开命令提示符窗口,并导航到 Android SDK 平台工具文件夹(通常情况下,SDK 平台工具文件夹位于 C:\Program Files (x86)\Android\android-sdk\platform-tools 中)。Open a command prompt window and navigate to the Android SDK platform-tools folder (typically, the SDK platform-tools folder is located at C:\Program Files (x86)\Android\android-sdk\platform-tools).

如果仅连接了单个设备(物理设备或仿真器),则可以通过输入以下命令查看日志:If only a single device (physical device or emulator) is attached, the log can be viewed by entering the following command:

$ adb logcat

另一种方法是通过命令行查看调试日志。Another option is to view the debug log via the command line. 打开终端窗口,并导航到 Android SDK 平台工具文件夹(通常情况下,SDK 平台工具文件夹位于 /Users/username/Library/Developer/Xamarin/android-sdk-macosx/platform-tools 中)。Open a Terminal window and navigate to the Android SDK platform-tools folder (typically, the SDK platform-tools folder is located at /Users/username/Library/Developer/Xamarin/android-sdk-macosx/platform-tools).

如果仅连接了单个设备(物理设备或仿真器),则可以通过输入以下命令查看日志:If only a single device (physical device or emulator) is attached, the log can be viewed by entering the following command:

$ ./adb logcat

如果连接了多个设备,则必须对设备进行显式标识。If more than one device is attached, the device must be explicitly identified. 例如,adb -d logcat 显示已连接的唯一物理设备的日志,而 adb -e logcat 显示运行中的唯一仿真器的日志。For example adb -d logcat displays the log of the only physical device connected, while adb -e logcat shows the log of the only emulator running.

通过输入 adb 和读取帮助消息,可以找到更多命令。More commands can be found by entering adb and reading the help messages.

写入调试日志Writing to the Debug Log

使用 Android.Util.Log 类方法可将消息写入“调试日志” 。Messages can be written to the Debug Log by using the methods of the Android.Util.Log class.

例如:For example:

string tag = "myapp";

Log.Info (tag, "this is an info message");

Log.Warn (tag, "this is a warning message");

Log.Error (tag, "this is an error message");

这将生成类似下面的输出:This produces output similar to the following:

I/myapp (11103): this is an info message

W/myapp (11103): this is a warning message

E/myapp (11103): this is an error message

也可使用 Console.WriteLine 写入调试日志 – 这些消息将在 logcat 中以略有不同的输出格式显示(调试 Android 上的 Xamarin.Forms 应用时,此方法非常有用) :It is also possible to use Console.WriteLine to write to the Debug Log – these messages appear in logcat with a slightly different output format (this technique is particularly useful when debugging Xamarin.Forms apps on Android):

System.Console.WriteLine ("DEBUG - Button Clicked!");

这将在 logcat 中生成类似下面的输出:This produces output similar to the following in logcat:

Info (19543) / mono-stdout: DEBUG - Button Clicked!

兴趣消息Interesting Messages

在读取日志时(尤其是在向其他用户提供日志代码片段时),浏览完整的日志文件通常非常麻烦。When reading the log (and especially when providing log snippets to others), perusing the log file in its entirety is often too cumbersome.

若要更加轻松地浏览日志消息,首先查找类似于下面的日志条目:To make it easier to navigate through log messages, start by looking for a log entry that resembles the following:

I/ActivityManager(12944): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=GcTest.GcTest/gctest.Activity1 } from pid 24175

具体而言,查找与也包含应用程序包名称的正则表达式匹配的行:In particular, look for a line matching the regular expression that also contains the name of the application package:

^I.*ActivityManager.*Starting: Intent

这是对应于活动开始的行,大多数 (并非全部)以下消息均应与应用程序相关。This is the line which corresponds to the start of an activity, and most (but not all) of the following messages should relate to the application.

请注意,每条消息均包含生成该消息的进程的进程标识符 (pid)。Notice that every message contains the process identifier (pid) of the process generating the message. 在上一 ActivityManager 消息中,进程 12944 生成了消息。In the above ActivityManager message, process 12944 generated the message. 若要确定哪个进程是正在调试的应用程序进程,请查找 mono.MonoRuntimeProvider 消息:To determine which process is the process of the application being debugged, look for the mono.MonoRuntimeProvider message:

I/ActivityThread( 602): Pub TouchTest.TouchTest.__mono_init__: mono.MonoRuntimeProvider

此消息来自已启动的进程。This message comes from the process that was started. 包含此 pid 的所有后续消息均来自同一进程。All subsequent messages that contain this pid come from the same process.

平板Android调试打开log,Android 调试日志相关推荐

  1. android studio 抓log,Android studio保存logcat日志到本地的操作

    windows环境下 1.输出logcat日志到本地文件 adb logcat -> F:/logcat.txt 2.输出带时间的logcat日志到本地文件: adb logcat -v thr ...

  2. 02_JNI中Java代码调用C代码,Android中使用log库打印日志,javah命令的使用,Android.mk文件的编写,交叉编译

     1  编写以下案例(下面的三个按钮都调用了底层的C语言): 项目案例的代码结构如下: 2 编写DataProvider的代码: package com.example.ndkpassdata; ...

  3. android第三方打开文件,Android第三方文件选择器aFileChooser使用方法详解

    aFileChooser是android平台上的一个第三方文件选择器,其在github上的项目主页是:https://github.com/iPaulPro/aFileChooser aFileCho ...

  4. android scheme打开app,android 通过Scheme链接启动app

    一.参考文章: http://www..com/shadajin/p/5724117.html http://jingyan.baidu.com/article/c45ad29cd6b15505175 ...

  5. android 如何打开s3db,Android开发教程:使用已有的SQL数据库

    极品好儿媳全文阅读,燃料乙醇放量,嘉兴办公家具,应向阳,58会展网,证书挂靠,鱼缸清洗,qq蜡笔小新头像 我在sqliteadmin 创建好数据库StuDB,里面的表如下: 650) this.wid ...

  6. android 混淆 去掉log,Android去掉/混淆Log,反编译都看不到

    原标题:Android去掉/混淆Log,反编译都看不到 出发点: 当然是由于编程习惯太好,打了一堆中文log,其实只是想给测试看.然而如果包被反编译,看log基本都能理解流程了,有点尴尬.所以此文主要 ...

  7. android 代码打开权限,android开发权限询问的示例代码

    现在基于信息安全问题,特别是版本是23以上权限越严格. 特别是拍照,读,写权限 一般权限允许过,下次就不用询问了的,所以很多应用都喜欢在首页或者启动页直接询问,不允许的就用不了1.下面给出封装好的类, ...

  8. android默认打开adb,android user 版本如何默认adb调试为打开(示例代码)

    A. 软件准备 user版本需要先打开USB debug开关,打开方式如下: 1.打开usb调试 build/core/main.mk 请将user版本下也改为ro.debuggable = 1 if ...

  9. Android关机充电打开log,Android关机log

    Android 版本:4.4 Linux 版本:3.10 查看关机log,分析启动原因,是否重启,正常关机. 关机原因位置:/proc/sys/kernel/boot_reason 重新启动: C:\ ...

  10. android main system log,android日志缓冲区,system,radio,main,events是什么意思啊?

    满意答案 a568103627 2015.06.11 采纳率:57%    等级:11 已帮助:6453人 logcat使用方法如下所示[1]: [adb] logcat [] ... [] ... ...

最新文章

  1. NCEPU:线下组队学习周报(009)
  2. 火星上真的有液态水?!欧洲科学家新发现登上《自然·天文学》
  3. 导出真实表格显示列数不能超过256_平均月薪真有6万5?说说我所知道的金融人真实薪酬...
  4. 若依的框架怎么样_基于bootstrapTable的若依框架如何获取表格选中行的整行数据?...
  5. hashset java 键值对_Java中的各个容器的性能对比
  6. Scrapy-Item Pipeline(项目管道)
  7. 第2章[2.3] 基于Ext JS的MVC/MVVM架构的应用开发模式
  8. cout不明确什么意思_年轻人不讲武德是什么梗和意思 年轻人不讲武德梗出处
  9. Java基础面试题整理-50题(附答案)
  10. Mybatis中Mapper标签总结大全
  11. VMware 安装 Linux 系统
  12. AD9361参数设置总结
  13. 元宇宙中N中AR试鞋体验
  14. TL-WDN5200H无线usb网卡在Linux上的使用
  15. 可控硅BT136典型应用电路
  16. 显卡出问题,花屏,显示蓝条了,分辨率800*600,想办法终于把问题定位了
  17. 如果英剧《黑镜子》拍第三季,你来写一集剧本策划,你想写一个什么样的故事呢? - 知乎...
  18. Java程序通过代理访问网络
  19. python爬虫案例教程~淘女郎、百度百科文本、规范化爬虫
  20. html怎么让图片自动动起来,使用css让图片动起来

热门文章

  1. npm常用命令及参数详解
  2. [Java面试十]浏览器跨域问题.
  3. 如何实现与硅谷技术零距离
  4. Silverlight 3.0正式版RTW的发布日期
  5. exists/not exists(2020-3-27)
  6. 镇魂街武神躯怎么修改服务器,镇魂街武神躯怎么重置守护灵_守护灵重置方法_3DM手游...
  7. SpringBoot Maven repackage failed: Unable to find a single main class from the following candidates
  8. JQuery的父、子、兄弟节点查找,节点的子节点循环
  9. 大白话5分钟带你走进人工智能-第一节开篇介绍以及线性回归简介篇
  10. 正确的Kado ED「永遠のこたえ」