在Linux系统中,日志记录级别的配置通常涉及以下几个方面:
syslog、rsyslog或systemd-journald。syslog 或 rsyslog编辑配置文件:
syslog的配置文件通常是 /etc/syslog.conf。rsyslog的配置文件可能是 /etc/rsyslog.conf 或 /etc/rsyslog.d/ 目录下的文件。设置日志级别:
auth, authpriv, cron, daemon, kern, local0 到 local7 等。emerg, alert, crit, err, warning, notice, info, 和 debug。示例配置:
# 设置所有设施的日志级别为 warning
*.*;auth,authpriv.none -/var/log/messages
# 设置 auth 和 authpriv 的日志级别为 info
auth,authpriv.* -/var/log/secure
# 设置 cron 的日志级别为 notice
cron.* -/var/log/cron
# 设置 daemon 的日志级别为 debug
daemon.* -/var/log/daemon.log
# 设置 kern 的日志级别为 err
kern.* -/var/log/kern.log
# 设置 local0 到 local7 的日志级别为 info
local0.*;local1.*;local2.*;local3.*;local4.*;local5.*;local6.*;local7.* -/var/log/local.log
重启服务:
syslog 或 rsyslog 服务以应用更改。sudo systemctl restart rsyslog
systemd-journald编辑配置文件:
systemd-journald 的配置文件通常是 /etc/systemd/journald.conf。设置日志级别:
示例配置:
[Journal]
SystemMaxUse=500M
SystemKeepFree=100M
SystemMaxFileSize=50M
SystemMaxFiles=5
重启服务:
systemd-journald 服务以应用更改。sudo systemctl restart systemd-journald
每个应用程序可能有自己的日志记录机制和配置文件。以下是一些常见应用程序的日志配置示例:
编辑配置文件:
/etc/httpd/conf/httpd.conf 或 /etc/apache2/apache2.conf。设置日志级别:
LogLevel 指令设置日志级别。LogLevel warn
重启服务:
sudo systemctl restart httpd
编辑配置文件:
/etc/nginx/nginx.conf。设置日志级别:
error_log /var/log/nginx/error.log debug;
重启服务:
sudo systemctl restart nginx
通过以上步骤,你可以根据需要配置Linux系统的日志记录级别,以满足不同的监控和调试需求。