如何保存logcat的消息 [英] How are logcat messages saved

查看:298
本文介绍了如何保存logcat的消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在哪里的Andr​​oid logcat的文件存储在哪里?我知道logcat的是保存为在内核的内部环形缓冲器,其大小为256kb。应用程序使用一种特殊的API来请求内核保存日志。

Following Where are Android logcat files stored? I learn that logcat is saved as an internal ring buffer in the kernel, which is sized 256kb. Applications use a special API to ask the kernel to save logs.

我的设备日志wayyyyyy较大。我知道这是因为当我亚行logcat> adblogcat.txt 我得到一个非常大的文件。这意味着东西清除内核缓冲区,并将其存储在文件系统(?)和亚行logcat 从这个较大的文件中读取。

My device logs are wayyyyyy larger. I know this because when I adb logcat > adblogcat.txt I get a really large file. This implies that "something" clears the kernel buffers and stores them in the file system (?) and adb logcat reads from this larger file.

谁能解释这是如何工作的?我期待到 https://github.com/cgjones /android-system-core/blob/master/logcat/logcat.cpp 我无法理解的具体细节。

Can anyone explain how this works? I am looking into https://github.com/cgjones/android-system-core/blob/master/logcat/logcat.cpp and I cannot understand the exact details.

奖励积分的人谁介绍了在重新启动时会发生什么,是保存重启的日志?

Bonus points to someone who explains what happens on reboot, is the log saved between reboots?

推荐答案

下面是我的理解有关的logcat,也许有一些失误,欢迎任何意见:

Here is my understanding about logcat, maybe there are some mistakes, welcome any comments:

  1. 关于手机中的日志文件 从 框架/基/核心/ JNI / android_util_Log.cpp 我们可以看到所有的日志将被写入的/ dev /日志/ 文件夹中的设备的默认。 主要将写入的/ dev /日志/主 电台将被写入的/ dev /日志/收音机 ... 因为所有的I /操作员系统的O文件。所以当手机重新启动后会被清除。并且这些文件的大小有一定的局限性,如果大小达到限制时,旧日志将被覆盖。

  1. About log file in the phone From the frameworks/base/core/jni/android_util_Log.cpp we can see all log will be written into /dev/log/ folder in your devices at default. main will be written into /dev/log/main radio will be written into /dev/log/radio ... because all are I/O files of operator system. So there will be cleared when the phone is rebooted. And these files size have some limitation, if the size reaches the limitation, the old log will be overridden.

关于logcat的 logcat的是一个工具来读取或再输出的日志文件。它被安装在系统/斌/文件夹中的电话。我不看的每一个code logcat.cpp ;但我可以说的logcat的应用程序会读取系统/ logcat中/主日志文件在默认情况下,输出他们在屏幕或根据您使用的参数文件。

About Logcat Logcat is a tool to read or re-output the log files. It is installed in the system/bin/ folder in the phone. I don't read the every code of logcat.cpp; but I can say the logcat application will read the log file in system/logcat/main at default and output them in the screen or the file based the parameters you use.

关于日志是如何产生的。 如果你看到源$ C ​​$ C android.util.log ,你可以找到所有log.d / log.e将使用JNI方法来写日志,日志文件,如上面提到的。

About how the log is generated. If you see the source code of android.util.log, you can find all log.d/log.e will use JNI method to write the log to log files, as mentioned above.

公共静态本地INT println_native(INT bufID,INT的优先级,字符串变量,字符串味精);

您可以找到JNI方法这里 。如果你有兴趣,你可以阅读源$ C ​​$ C发现它是什么做什么。

You can find the JNI method here. If you are interested it, you can read the source code to find what it is doing there.

保存的logcat你想要的特定文件 基于日志的I / O,开发人员可以编写一个应用程序日志保存到SD卡中的文件在手机中,让我们可以保持更多的日志或更大的日志文件。 最简单的方法是使用的Runtime.exec()执行logcat的应用程序: 您可以监视引导完成接收器,启动你的logcat命令来读取所有的logcat的日志到您自己的文件。

Save the logcat to specific file you want Based on the Log I/O, developer can write an application to save the log into a file in SD card in the phone so that we can keep the more logs or bigger log file. The most simplest method is use the Runtime.exec() to execute the logcat application: You can monitor the BOOT completed receiver to start your logcat command to read all logcat's log into your own files.

例如:

 String cmd = "logcat -v time -f yourown.file"
 Process process = Runtime.getRuntime().exec(cmd);

这篇关于如何保存logcat的消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆