在Ubuntu系统中,可以通过修改syslog配置文件来设置系统日志级别。以下是具体步骤:
方法一:使用rsyslog
配置文件
-
打开
rsyslog
配置文件:sudo nano /etc/rsyslog.conf
或者
sudo gedit /etc/rsyslog.conf
-
找到并修改日志级别: 在配置文件中,你可以看到类似以下的行:
# Log all kernel messages to the console. # Logging much else clutters up the screen. #kern.* /dev/console
你可以修改
kern.*
这一行来设置内核日志级别。例如,如果你想只记录错误及以上级别的日志,可以改为:kern.err /dev/console
其他日志级别包括:
emerg
:紧急情况,系统不可用alert
:警告,需要立即处理crit
:严重错误err
:错误warning
:警告notice
:通知info
:信息性消息debug
:调试信息
-
保存并退出编辑器。
-
重启
rsyslog
服务以应用更改:sudo systemctl restart rsyslog
方法二:使用journalctl
命令(适用于systemd)
如果你使用的是systemd,可以通过journalctl
命令来查看和设置日志级别。
-
查看当前日志级别:
journalctl --disk-usage
-
设置日志级别: 你可以通过修改
/etc/systemd/journald.conf
文件来设置日志级别。打开文件:sudo nano /etc/systemd/journald.conf
找到并修改以下行:
[Journal] SystemMaxUse=500M SystemKeepFree=100M SystemMaxFileSize=50M SystemMaxFiles=5
你可以添加或修改
SystemLogLevel
来设置日志级别:SystemLogLevel=debug
其他选项包括:
emerg
alert
crit
err
warning
notice
info
debug
-
保存并退出编辑器。
-
重启
systemd-journald
服务以应用更改:sudo systemctl restart systemd-journald
通过以上方法,你可以根据需要设置Ubuntu系统的日志级别。