在Ubuntu系统中,日志级别的设置通常涉及系统日志服务(如rsyslog或systemd-journald)以及特定应用程序的日志配置。以下是一些常见的方法来设置日志级别:
编辑rsyslog配置文件:
/etc/rsyslog.conf 文件或 /etc/rsyslog.d/50-default.conf 文件(具体路径可能因版本而异)。nano 编辑器打开配置文件:sudo nano /etc/rsyslog.conf。设置日志级别:
info:# 设置默认日志级别为 info
$DefaultLoggingLevel info
info 替换为你想要的日志级别,如 debug、notice、warning、err、crit、alert、emerg。重启rsyslog服务:
rsyslog 服务以应用更改:sudo systemctl restart rsyslog
编辑journald配置文件:
/etc/systemd/journald.conf 文件。# SystemMaxUse=50M
# SystemKeepFree=10M
# SystemMaxFileSize=50M
# RuntimeMaxUse=50M
# RuntimeKeepFree=10M
# RuntimeMaxFileSize=50M
# MaxRetentionSec=1d
# MaxFileSec=1h
SystemLogLevel 和 RuntimeMaxLevel 参数来设置日志级别,例如:SystemLogLevel=debug
RuntimeMaxLevel=debug
重启systemd-journald服务:
systemd-journald 服务以应用更改:sudo systemctl restart systemd-journald
许多应用程序都有自己的日志配置文件,你可以在这些文件中设置日志级别。例如:
Apache HTTP Server:
/etc/apache2/apache2.conf 或特定虚拟主机的配置文件,添加或修改 LogLevel 指令:LogLevel debug
Nginx:
/etc/nginx/nginx.conf,添加或修改 error_log 和 access_log 指令:error_log /var/log/nginx/error.log debug;
access_log /var/log/nginx/access.log debug;
你可以使用以下命令来检查当前的日志级别:
sudo getconf LOG_LEVEL
请注意,getconf LOG_LEVEL 可能不会显示所有可能的日志级别,具体取决于你的系统和配置。