在Ubuntu系统中,日志级别的设置通常涉及系统日志服务(如rsyslog
或systemd-journald
)以及特定应用程序的日志配置。以下是一些常见的方法来设置日志级别:
rsyslog
rsyslog
是Ubuntu默认的系统日志服务。你可以通过编辑其配置文件来设置日志级别。
打开 rsyslog
配置文件:
sudo nano /etc/rsyslog.conf
找到并修改日志级别: 在文件中找到类似以下的行:
# Log all kernel messages to the console.
# Logging much else clutters up the screen.
#kern.* /dev/console
你可以将 kern.*
改为所需的日志级别,例如 kern.debug
、kern.info
等。
重启 rsyslog
服务:
sudo systemctl restart rsyslog
systemd-journald
systemd-journald
是Ubuntu 16.04及更高版本中使用的系统日志服务。你可以通过编辑其配置文件来设置日志级别。
打开 journald
配置文件:
sudo nano /etc/systemd/journald.conf
找到并修改日志级别: 在文件中找到类似以下的行:
#SystemMaxUse=50M
#SystemKeepFree=10M
#SystemMaxFileSize=50M
#RuntimeMaxUse=50M
#RuntimeKeepFree=10M
#RuntimeMaxFileSize=50M
#MaxRetentionSec=1d
#MaxFileSec=1h
你可以添加或修改 SystemMaxLevel
和 RuntimeMaxLevel
参数来设置日志级别,例如:
SystemMaxLevel=debug
RuntimeMaxLevel=debug
重启 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;
通过编辑相应的配置文件并重启相关服务,你可以灵活地设置Ubuntu系统及其应用程序的日志级别。根据你的需求选择合适的方法进行配置。