Skip to main content

Rsyslog

Tutorials

    Chapter 23. Viewing and Managing Log Files Red Hat Enterprise Linux 7 | Red Hat Customer Portal 鳥哥私房菜 - 第十八章、認識與分析登錄檔 (vbird.org)

    整合特定應用程式

    情境一: 寫入日誌檔

    應用程式透過 rsyslog 協定寫入訊息,系統要輸出特定日誌檔。

    /etc/rsyslog.d/myapp.conf

    # Save db2audit log to db2audit
    # Test command:
    # logger -t db2audit -p user.info "Hello, This is Test Message"
    if $programname == 'db2audit' then action(type="omfile" file="/var/log/db2audit")

    TIP: 如果不用這判斷式,只用 user.* 格式,其他不相關的應用程式日誌也會一併寫入。

    情境二: 讀取日誌檔

    應用程式已經有自己的日誌檔,內容也符合 rsyslog 標準日誌格式,需要同步也寫到外部的日誌伺服器。

    /etc/rsyslog.d/myapp.conf

    $ModLoad imfile
    
    $InputFileName  /app/your-file.log 
    $InputFileTag   your-tag
    $InputFileStateFile     your-tag 
    $InputFileSeverity      info
    $InputFileFacility      local7 
    $InputRunFileMonitor
    $InputFilePersistStateInterval 1000 
    local7.*  @@remote-rsyslog-server:port

    FAQ

    日誌檔不明原因無法被寫入新日誌

    日誌檔一旦被編輯過就無法再被寫入,必須重啟 rsyslog 服務後才會恢復。