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

标签 linux syslog yocto bitbake

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

我有几个用例。为了简化,我想问一下如何配置 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 时,日志回绕。生成1个日志文件+1个log-rotate文件。

关于如何归档 syslog 写入无限长日志文件的任何想法?

我正在研究 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) 转到“系统日志实用程序”

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 守护进程的配置

此示例记录到限制为 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

现在它应该可以工作了!

关于linux - 如何在 yocto 中设置系统日志?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41868231/

相关文章:

linux - 即使是 root 也无法运行任何 shell 脚本

linux - 如何在 docker 实例中关闭 sendfile

c - 用于生成系统日志消息的 C 语言标准接口(interface)

c++ - 无法编译我的旧项目(使用 gcc)

linux - 如何打印命令的结果以及结果的计数?

linux - 事件包头如何进入 hci_send_req api 实现?

nginx - 为什么 rsyslog 用 #011 替换选项卡?

linux - 系统日志:进程特定的优先级

embedded-linux - Yocto 如何根据图像配方覆盖 linux rootfs 文件?

embedded-linux - 如何使用 Yocto 安装 SSH 主机 key