在init.rc启用logcat中 [英] Enabling logcat in init.rc

查看:1498
本文介绍了在init.rc启用logcat中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我追加init.rc在Android的根与

I'm appending init.rc in Android root with:

service logcat /system/bin/logcat -v long -f /mnt/sdcard/logcat.log

该解决方案不会产生任何日志。该logcat.log文件不存在。

This solution doesn't generate any logs. The logcat.log file doesn't exist.

我怎样才能开始通过init.rc收集logcat的输出?

How can i start gathering logcat output through init.rc ?

推荐答案

一对夫妇的东西,可能会导致上述问题:
1.你定义你的服务被称为logcat中。这看起来非常接近可能是什么保留/ pre-现有名称。我会选择一个更尊贵的服务名称。
2.没有为服务没有明确的启动触发,因此它完全依赖于它的定义(即其初始化阶段)的背景。挑错相(即太早),并到/ mnt甚至可能不存在。
3.该服务默认情况下会以root权限运行,因而logcat.log文件只能由root RW。也不好运行的进程的根。而且也不好强迫读者是root才能读取日志文件。

A couple of things that could be causing problems above: 1. you defined your service to be called logcat. That looks awfully close to what might be a reserved/pre-existing name. I would choose a more distinguished service name. 2. there is no explicit start trigger for the service, hence its entirely dependent on the context in which its defined (i.e. which init phase). Pick the wrong phase (i.e. too early) and /mnt may not even exist. 3. the service will by default be running as root and thus the logcat.log file will be rw only by root. Not good to run processes as root. And not good to force readers to be root in order to read the log file.

在这里,我来实现你希望做什么办法。

Here the approach I've used to achieve what you're looking to do.

问题:通常情况下,Android的日志信息保留在内核的(挥发性)内存,因此不会在重新启动后生存。

Problem: Ordinarily, Android log messages remain in the kernel’s (volatile) memory only and thus doesn’t survive across reboots.

解决方案:为了保持在重新启动后的日志信息需要被写入到永久存储(即文件系统)他们。下面code定义了由Android初始化期间启动这样的服务。

Solution: To retain those log messages across reboots requires them to be written to persistent storage (i.e. the filesystem). The following code defines such a service that is started by Android during init.

步骤1,定义了Android init进程将产生做这个活动相关的服务。这正好在init.rc.

Step 1, define a service that the Android init process will spawn to do this activity. This goes in init.rc.

service persistentLogging /system/bin/logcat -r 1024 -n 9 -v threadTime -f /cache/logs/log
    user system
    group system log
    disabled

有关上述注意事项:

Notes about the above:


  1. 它将创建一个名为persistentLogging服务的启动触发(将在下面的第二个步骤进行说明)。

  2. 它要求的logcat执行滚动日志文件(包括10个文件/ 1Mb的每个)的目录 - /缓存/日志(即日志,log.1,log.2,... log.9)。调整,以满足您的需求。

  3. 服务是作为系统用户运行。这意味着日志文件将被读取+仅由系统写。如果您的应用程序具有系统权限,那么你就可以读取日志文件。我也定义的服务是日志组在太多,因为虽然自文件是不按组的一个有争议的问题可读似乎合适。

  4. 服务最初是被禁用。它将由下面定义的触发器启动

  5. 服务未ONESHOT。因此,它死了,Android将尝试重新启动它。

步骤2中,定义一个触发启动该服务。这还要在你的init.rc文件。

Step 2, define a trigger for starting the service. This also goes in your init.rc file.

on post-fs
    mkdir /cache/logs 0775 system log
    start persistentLogging

有关上述注意事项:

Notes about the above:


  1. 的命令中的FS后阶段,使文件系统后,分区已安装它们发生,当其它系统目录有他们的权限变化触发。理想情况下,该服务应该开始尽可能晚,因为它并不重要或通过任何其它的启动活动中使用。

  2. 触发第一个启动服务之前创建目标目录。记住mkdir命令语法由init.rc语言定义的。在Android的这种语法不是sh句法尽管它已经看起来很像吧。

  3. eventhough上面的日志服务没有启动,直到初始化的后FS阶段,仍将抛售,因为内核的启动开始的所有日志信息,因为这些日志消息已经在内核缓冲区和这种日志记录服务仅仅是复制这些消息记录到文件。

  4. 虽然上述两个最终code片段需要出现在init.rc文件,它是更易于维护,如果这些被添加到init的。$ {} ro.hardware rc文件的设备定义。例如init.freescale.rc这是由init.rc自动包括在内。

这篇关于在init.rc启用logcat中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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