在CentOS系统中,syslog的日志级别可以通过修改/etc/rsyslog.conf
文件来设置。以下是具体的步骤:
/etc/rsyslog.conf
打开配置文件:
sudo vi /etc/rsyslog.conf
找到日志级别设置部分: 通常在文件的顶部或底部会有类似以下的配置段落:
# Log all kernel messages to the console.
# Logging much else clutters up the screen.
#kern.* /dev/console
& ~
# Send system startup messages to the syslog server.
auth,authpriv.* /var/log/secure
mail.* -/var/mail/root
cron.* /var/log/cron
# Everybody gets emergency messages
*.emerg.* /dev/console
修改日志级别:
*.emerg.*
表示所有级别的紧急消息都会被记录到控制台。*.alert.*
表示所有级别的警报消息都会被记录。*.crit.*
表示所有级别的严重消息都会被记录。*.err.*
表示所有级别的错误消息都会被记录。*.warning.*
表示所有级别的警告消息都会被记录。*.notice.*
表示所有级别的通知消息都会被记录。*.info.*
表示所有级别的信息消息都会被记录。*.debug.*
表示所有级别的调试消息都会被记录。例如,如果你只想记录错误及以上级别的日志,可以将配置修改为:
auth,authpriv.* /var/log/secure
mail.* -/var/mail/root
cron.* /var/log/cron
kern.* /dev/console
user.* /var/log/messages
# Set default logging level to err
*.*;auth,authpriv.none;news.crit;mail.none /var/log/messages
保存并退出:
按 Esc
键,然后输入 :wq
并按回车键保存并退出。
重启rsyslog服务:
sudo systemctl restart rsyslog
logger
命令临时设置日志级别如果你只想临时更改日志级别,可以使用logger
命令。例如,将所有日志级别设置为info
:
sudo logger -p local0.info "This is an info message"
通过以上步骤,你可以成功地在CentOS系统中设置syslog的日志级别。