我喜欢配置syslog。似乎不止一种设置syslog的方法。我要求实现此目的的常用方法/步骤。
我有几个用例。为简化起见,我想问一下如何配置syslog以在/var/log/中写入一个无限长的日志文件。
步骤如下:
1.)配置哪些消息
1.1)创建自己的“syslog.conf”(定义/var/log/myLog)
1.2)将其附加到“recipes-core/busybox”
2.)配置如何记录
??
我找到了两个可能的位置:
@ meta-poky
->“元-poky/食谱核心/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时,日志将自动换行。生成一个日志文件+一个日志轮换文件。
有什么想法如何归档syslog写入无限长的日志文件吗?
我正在Yocto krogoth分支+ meta-atmel/meta_openembedded(也@ krogoth)上工作。
最佳答案
通过检查syslog和busybox的来源,我找到了可能的解决方案。此解决方案显示了如何配置syslog以登录两个最大10MByte的日志:
1.)获取有效的syslog构建配置
1.1)下载busybox-> git/busybox
1.2)通过bitbake-> bitbake busybox构建busybox
1.3)将defconfig文件复制到下载的busybox-> cp/defconfig git/busybox/
1.4)制作menueconfig
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 KB。 “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中设置syslog?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41868231/