linux syslog 日志采集系统搭建 (3)

4. template(日志格式控制)
        使用template定义日志格式模板,可以规范不通的类型的日志,很方便我们查看,使用起来也很简单,但是template的定义必须放在rsyslog.conf的顶端。
            1: $template myFormat,"%timestamp%  %hostname% %msg%\n"
            2:    $ActionFileDefaultTemplate myFormat
        第一行我们定义了一个名为myFormat的模板,第二行的意思是把我们定义的myFormat作为rsyslog的默认模板。如果只是需要在特定日志上套用这个模板可以这样写
            1:$template myFormat,"%timestamp%  %hostname%  %msg%\n"
        如果希望手机到的日志不是使用hostname标识,而是ip地址标识可以这样写
            $template myFormat,"%timestamp% %fromhost-ip%%msg%\n"
            $ActionFileDefaultTemplate myFormat

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zgdgjj.html