如何在 yocto 中设置系统日志?

Posted

技术标签:

【中文标题】如何在 yocto 中设置系统日志?【英文标题】:How to setup syslog in yocto? 【发布时间】:2017-01-26 06:57:17 【问题描述】:

我喜欢配置系统日志。似乎设置系统日志的方法不止一种。我要求的是常见的方法/步骤来做到这一点。

我有几个用例。为了简单起见,我想问一下如何配置 syslog 以在 /var/log/ 中写入无限长的日志文件。

以下步骤:

1.) 配置什么消息

1.1) 创建自己的“syslog.conf”(定义/var/log/myLog)

1.2) 将其附加到“recipes-core/busybox”

2.) 配置如何记录

??

我找到了两个可能的地方:

@meta-poky -> “meta-poky/recipes-core/busybox/busybox/poky-tiny/defconfig”

#
# System Logging Utilities
#
CONFIG_SYSLOGD=y
CONFIG_FEATURE_ROTATE_LOGFILE=y
CONFIG_FEATURE_REMOTE_LOG=y
CONFIG_FEATURE_SYSLOGD_DUP=y
CONFIG_FEATURE_SYSLOGD_CFG=y
CONFIG_FEATURE_SYSLOGD_READ_BUFFER_SIZE=256
CONFIG_FEATURE_IPC_SYSLOG=y
CONFIG_FEATURE_IPC_SYSLOG_BUFFER_SIZE=16
CONFIG_LOGREAD=y
CONFIG_FEATURE_LOGREAD_REDUCED_LOCKING=y
CONFIG_KLOGD=y
CONFIG_FEATURE_KLOGD_KLOGCTL=y
CONFIG_LOGGER=y

添加/更改:

"CONFIG_FEATURE_ROTATE_LOGFILE=n" by adding that line to meta-mylayer/conf/layer.conf"

等等

???

@"/etc/syslog-startup.conf"

# This configuration file is used by the busybox syslog init script,
# /etc/init.d/syslog[.busybox] to set syslog configuration at start time.

DESTINATION=file        # log destinations (buffer file remote)
LOGFILE=/var/log/messages   # where to log (file)
REMOTE=loghost:514      # where to log (syslog remote)
REDUCE=no           # reduce-size logging
DROPDUPLICATES=no       # whether to drop duplicate log entries
#ROTATESIZE=0           # rotate log if grown beyond X [kByte]
#ROTATEGENS=3           # keep X generations of rotated logs
BUFFERSIZE=64           # size of circular buffer [kByte]
FOREGROUND=no           # run in foreground (don't use!)
#LOGLEVEL=5         # local log level (between 1 and 8)

在 systemV 初始化脚本“/etc/init.d/syslog.bussybox”中,文件“/etc/syslog-startup.con”被读取并用于配置。

系统行为:

运行我的系统时,当日志文件达到 200kBytes 时,日志会自动换行。生成一个日志文件 + 一个日志循环文件。

任何想法如何归档系统日志写入无限长的日志文件?

我正在开发 Yocto krogoth 分支 + meta-atmel / meta_openembedded(@krogoth 也是)。

【问题讨论】:

【参考方案1】:

通过检查 syslog 和 busybox 的来源,我找到了一个可能的解决方案。此解决方案展示了如何配置 syslog 以登录两个最大 10MByte 的日志:

1.) 获取有效的 syslog 构建配置

1.1) 下载busybox -> git/busybox

1.2) 通过 bitbake 构建busybox -> bitbake busybox

1.3) 复制defconfig 文件到下载的busybox -> cp /defconfig git/busybox/

1.4) 制作菜单配置

1.5) 转到“系统日志记录实用程序”

1.6) 取消选择 klogd,因为它可以与 printk 发生冲突

1.7) 保存到“defconfig”

#
# System Logging Utilities
#
# CONFIG_KLOGD is not set
# CONFIG_FEATURE_KLOGD_KLOGCTL is not set
CONFIG_LOGGER=y
CONFIG_LOGREAD=y
CONFIG_FEATURE_LOGREAD_REDUCED_LOCKING=y
CONFIG_SYSLOGD=y
CONFIG_FEATURE_ROTATE_LOGFILE=y
CONFIG_FEATURE_REMOTE_LOG=y
CONFIG_FEATURE_SYSLOGD_DUP=y
CONFIG_FEATURE_SYSLOGD_CFG=y
CONFIG_FEATURE_SYSLOGD_READ_BUFFER_SIZE=256
CONFIG_FEATURE_IPC_SYSLOG=y
CONFIG_FEATURE_IPC_SYSLOG_BUFFER_SIZE=64
CONFIG_FEATURE_KMSG_SYSLOG=y

2.) 设置您的日志配置

创建“syslog.conf”并输入规则: 这是一个例子:

#
#  /etc/syslog.conf     Configuration file for busybox's syslogd utility
#

kern.notice /var/log/messages


#
# my software messages
#
user.err    /var/log/mySWError
user.*      /var/log/mySWFull
local0.*    /var/log/mySWFull
local0.err  /var/log/mySWError
#
#this prevents from logging to default log file (-O FILE or /var/log/messages)
#
*.*                                     /dev/null

3.) 修改busybox syslog deamon的配置

此示例记录到限制为 10 MB 的文件。如果未设置“ROTATESIZE”,则 syslog 将日志文件大小自动设置为 200 kBytes。 “syslog-startup.conf”的内容如下:

# This configuration file is used by the busybox syslog init script,
# /etc/init.d/syslog[.busybox] to set syslog configuration at start time.

DESTINATION=file        # log destinations (buffer file remote)
#LOGFILE=/var/log/messages  # where to log (file)
REMOTE=loghost:514      # where to log (syslog remote)
REDUCE=no           # reduce-size logging
DROPDUPLICATES=no       # whether to drop duplicate log entries
ROTATESIZE=10000        # rotate log if grown beyond X [kByte]
#ROTATEGENS=3           # keep X generations of rotated logs
BUFFERSIZE=64           # size of circular buffer [kByte]
FOREGROUND=no           # run in foreground (don't use!)
#LOGLEVEL=5         # local log level (between 1 and 8)

4.) 将配置放入 yocto build

4.1) 在您自己的层(元自定义)中创建以下目录结构:

meta-custom/recipes-core/
meta-custom/recipes-core/busybox/
meta-custom/recipes-core/busybox/busybox

4.2) 复制到“meta-custom/recipes-core/busybox/busybox”:

defconfig
syslog.conf
syslog-startup.conf

4.3) 在“meta-custom/recipes-core/busybox/”“busybox_1.24.1.bbappend”中创建。如果您使用较旧/较新版本的busybox,您需要将“1.24.1”号码更改为您的号码。您可以在“/poky/meta/recipes-core/busybox/”中找到您的版本

将这两行添加到这个文件中:

FILESEXTRAPATHS_prepend := "$THISDIR/$PN:"
FILESEXTRAPATHS_prepend := "$THISDIR/$PN/poky-tiny:"

5.) 构建您自定义的系统日志

bitbake busybox

并将其传输到图像的rootfs中

bitbake core-image-minimal

现在应该可以了!

【讨论】:

【参考方案2】:

添加到 Stefan Jaritz 评论中,您只需发出即可跳过下载步骤

bitbake busybox -c devshell

然后运行make menuconfig 并从中获取新的配置文件。请注意,这将默认使用 Yocto 的 defconfig,因此您无需担心“这个默认配置是什么”。

【讨论】:

以上是关于如何在 yocto 中设置系统日志?的主要内容,如果未能解决你的问题,请参考以下文章

python 如何在tensorflow中设置日志记录级别

如何使用winston在子目录而不是根目录中设置日志?

如何在运行时在 org.jboss.logging 中设置日志记录

在 Yocto ext4 映像中设置 Linux 功能

在 MISRA C 中设置日志级别的标准方法

通过环境变量在 Spring Boot 中设置日志记录级别