linux - 有没有办法从 linux 的系统日志中检索消息的严重级别?

标签 linux ubuntu rsyslog

有没有办法从 linux 的系统日志中检索消息的严重性级别?成为root后我尝试了以下操作:

 1.  sudo vim rsyslog.conf
 2.  tried to add following lines of code so that I could send every level 
     to separate files 

  ## ------------------------------------------------------------------ #
  ## All levels in a seperate file
  *.emerg                         -/var/log/log.0_emergency
  *.alert;*.!emerg                -/var/log/log.1_alert
  *.crit;*.!alert                 -/var/log/log.2_critical
  *.err;*.!crit                   -/var/log/log.3_error
  *.warning;*.!err                -/var/log/log.4_warning
  *.notice;*.!warning             -/var/log/log.5_notice
  *.info;*.!notice                -/var/log/log.6_info
  *.debug;*.!info                 -/var/log/log.7_debug

 3.  :wq  to save and quit vim

但是,这并没有得到保存。有人可以指导我吗?

最佳答案

我对旧格式不太熟悉(而且我没有测试过),但这可能会满足您的需求:

## ------------------------------------------------------ #
## All levels in a seperate file
*.emerg                         -/var/log/log.0_emergency
& stop

*.alert;*.!emerg                -/var/log/log.1_alert
& stop

*.crit;*.!alert                 -/var/log/log.2_critical
& stop

*.err;*.!crit                   -/var/log/log.3_error
& stop

*.warning;*.!err                -/var/log/log.4_warning
& stop

*.notice;*.!warning             -/var/log/log.5_notice
& stop

*.info;*.!notice                -/var/log/log.6_info
& stop

*.debug;*.!info                 -/var/log/log.7_debug
& stop

这最终会成为我的方法,因为我喜欢“高级”格式的精确度:
if ($syslogfacility-text == 'auth') 
    or ($syslogfacility-text == 'authpriv') then {

    action(
        name="auth-log"
        type="omfile"
        file="/var/log/auth.log")

    stop
}

# Keep cron messages in their own dedicated file
if ($syslogfacility-text == 'cron') then {
    action(
        name="cron-log"
        type="omfile"
        file="/var/log/cron.log")

    stop
}

根据设备、严重性、程序名称或任何数量的其他消息或系统属性,设置尽可能多的这些 block 。

文件:
  • http://www.rsyslog.com/doc/v8-stable/configuration/conf_formats.html
  • http://www.rsyslog.com/doc/v8-stable/configuration/properties.html
  • http://www.rsyslog.com/doc/v8-stable/configuration/filters.html

  • 编辑:代表太低,无法回复评论(奇怪的设计选择),所以在这里发布回复。

    重新保存文件的方法:

    If you are referring to "saving" in the sense of your modifications to the file, make sure that you are modifying the correct file. sudo nano /etc/rsyslog.conf and then make your changes. ctrl-x to attempt to quit, answer Y to saving the changes. Run sudo rsyslogd -N2 to test your configuration and then restart rsyslog via sudo service rsyslog restart

    关于linux - 有没有办法从 linux 的系统日志中检索消息的严重级别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49204605/

    相关文章:

    linux - Debian - GIT 从 1.5 升级到 1.7

    linux - 如何更新ubuntu中已经安装的应用程序?

    mysql - 尝试使用 drush 启用 drupal 模块的引导错误

    ubuntu - 仅使用 Python 3 进行 ROS 旋律安装并且不会弄乱系统库?

    sql-server - Linux 上的 Cakephp2 不能与 Sql Server (mssql) 一起使用

    c - 最新的系统日志消息被延迟

    linux - 我在 Linux 上的简单守护程序应该在哪个系统用户上默认运行以获得最佳兼容性?

    linux - 如何将树和 wc -l 结合起来?

    nginx - 如何通知资源是否在 nginx 中完全下载

    mysql - 如何在 Rsyslogd 中为 IP 地址设置特定规则并将其发送到 mysql 服务器