当前位置: 代码迷 >> 综合 >> yocto syslog配置深入解析
  详细解决方案

yocto syslog配置深入解析

热度:4   发布时间:2024-02-11 01:32:06.0

1、 配置完成的结果

1、配置完成后/etc目录下会有syslog.conf文件

在这里插入图片描述
2、配置完成后/var/log下可以看到logfile,size最大为2048k,可以缓存两个副本
在这里插入图片描述

2、配置及过程解析

1、首先看syslog的源码
yocto/build/downloads/busybox-1.29.2.tar.bz2软件包里,
解压后可以看到:/build/downloads/busybox-1.29.2/sysklogd/syslogd.c

static const struct init_globals init_data = {.logFile = {.path = "/var/log/messages", //定义了默认的logfile.fd = -1,},
#ifdef SYSLOGD_MARK.markInterval = 20 * 60,
#endif.logLevel = 8,
#if ENABLE_FEATURE_ROTATE_LOGFILE.logFileSize = 200 * 1024, //定义了logfile的缓存大小为200k,后面介绍怎么改成2048k.logFileRotate = 1,  //定义了缓冲文件为1,后面介绍怎么改为2
#endif

2、看syslog配置文件和解析文件

目录:meta-asr-ipc/recipes-core/busybox/files/syslog-startup.conf

syslog-startup.conf重新配置了syslog的大小,保存目录,远程日志端口

cat 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=2048                 # rotate log if grown beyond X [kByte]
ROTATEGENS=2                    # 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)

配置syslog-startup.conf 和syslog.conf的文件
./meta-asr-ipc/recipes-core/busybox$ cat busybox_%.bbappend


```powershell
do_install_append () {if grep -q "CONFIG_SYSLOGD=y" ${B}/.config; then#把信息写入目标文件的syslog.conf echo "kern.*;user.* /var/log/kernel.log" >> ${D}${sysconfdir}/syslog.conf fiif ${@bb.utils.contains('DISTRO_FEATURES','sysvinit','false','true',d)} && type update-rc.d >/dev/null 2>/dev/null; then#把本地的syslog-startup.conf拷贝到目标文件install -m 644 ${WORKDIR}/syslog-startup.conf ${D}${sysconfdir}/syslog-startup.conffi
}

3、syslog.conf源文件位置

./poky/meta/recipes-core/busybox/files$ ls syslog.conf

4、syslog脚本文件

./poky/meta/recipes-core/busybox/files$ ls syslog

Syslog解析过程:通过分析syslog-startup.conf,取出其中的参数进行配置

set -e
#判断是否存在/etc/syslog-startup.conf,否则使用源码配置
if [ -f /etc/syslog-startup.conf ]; then 
#运行配置文件. /etc/syslog-startup.conf         
LOG_LOCAL=0LOG_REMOTE=0
#循环所有的变量for D in $DESTINATION; do if [ "$D" = "file" ]; then#如果存在LOGFILE,则使用此参数if [ -n "$LOGFILE" ]; thenSYSLOG_ARGS="$SYSLOG_ARGS -O $LOGFILE"Fi#如果存在ROTATESIZE,则添加此参数if [ -n "$ROTATESIZE" ]; then SYSLOG_ARGS="$SYSLOG_ARGS -s $ROTATESIZE"Fi#如果存在ROTATEGENS,则添加此参数if [ -n "$ROTATEGENS" ]; thenSYSLOG_ARGS="$SYSLOG_ARGS -b $ROTATEGENS"fiLOG_LOCAL=1elif [ "$D" = "remote" ]; thenSYSLOG_ARGS="$SYSLOG_ARGS -R $REMOTE"LOG_REMOTE=1fidoneif [ "$LOG_LOCAL" = "1" -a "$LOG_REMOTE" = "1" ]; thenSYSLOG_ARGS="$SYSLOG_ARGS -L"fiif [ "$REDUCE" = "yes" ]; thenSYSLOG_ARGS="$SYSLOG_ARGS -S"fiif [ "$DROPDUPLICATES" = "yes" ]; thenSYSLOG_ARGS="$SYSLOG_ARGS -D"Fi#如果存在ROTATEGENS,则添加此参数if [ -n "$LOGLEVEL" ]; thenSYSLOG_ARGS="$SYSLOG_ARGS -l $LOGLEVEL"fi
else# default: log to 16K shm circular bufferSYSLOG_ARGS="-C"
fi

5、 通过.bb文件添加syslog syslog.conf syslog-startuo.conf

if grep -q "CONFIG_SYSLOGD=y" ${B}/.config; theninstall -m 0755 ${WORKDIR}/syslog ${D}${sysconfdir}/init.d/sysloginstall -m 644 ${WORKDIR}/syslog-startup.conf ${D}${sysconfdir}/syslog-startup.confinstall -m 644 ${WORKDIR}/syslog.conf ${D}${sysconfdir}/syslog.conf
fi

syslog功能解析可参考:https://blog.csdn.net/sssddd12345_/article/details/107856253