【问题标题】:Is there any way to retrieve the severity level of the messages from system log in linux?有没有办法从 linux 的系统日志中检索消息的严重级别?
【发布时间】:2018-08-18 15:58:13
【问题描述】:

有什么方法可以从 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

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

【问题讨论】:

    标签: linux ubuntu rsyslog


    【解决方案1】:

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

    ## ------------------------------------------------------ #
    ## 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
    }
    

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

    文档:

    编辑:rep 太低,无法回复 cmets(奇怪的设计选择),所以在这里发布回复。

    关于如何保存文件:

    如果您在修改的意义上指的是“保存” 文件,请确保您正在修改正确的文件。 sudo nano /etc/rsyslog.conf 然后进行更改。 ctrl-x 尝试 要退出,回答 Y 以保存更改。运行sudo rsyslogd -N2 到 测试你的配置,然后通过sudo service rsyslog restart重新启动rsyslog

    【讨论】:

    • 你是如何保存 rsyslog.conf 文件的? @deoren
    • @Gayatri 修改了我原来的答案。 Stack Exchange 移动应用程序很固执,不允许在此处发布完整回复。
    猜你喜欢
    • 1970-01-01
    • 2012-09-29
    • 2015-06-16
    • 1970-01-01
    • 1970-01-01
    • 2021-11-25
    • 1970-01-01
    • 1970-01-01
    • 2021-11-02
    相关资源
    最近更新 更多