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

How to setup syslog in yocto?

我喜欢配置系统日志。似乎设置系统日志的方法不止一种。我要求通用 way/steps 来做到这一点。

我有几个用例。为了简化,我想问一下如何配置 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

add/change:

"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 时日志回绕。生成 1 个日志文件 + 1 个日志循环文件。

知道如何归档系统日志写入的无限长日志文件吗?

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

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

1.) 获取有效的系统日志构建配置

1.1) 下载busybox -> git/busybox

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

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

1.4) 制作菜单配置

1.5) 转到 "System Logging Utilities"

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):

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" 中创建。如果您使用 older/newer 版本的 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

现在应该可以了!

添加到 Stefan Jaritz 评论中,您只需发出

即可跳过下载步骤
bitbake busybox -c devshell

然后 运行 make menuconfig 并从中获取新的配置文件。请注意,这将默认使用 Yocto 的 defconfig,因此您无需担心 "what's this default config".