标签:rsyslog
有个新需求:postgresql的日志在rsyslog服务器中的日志要分开打,根据priority,即:
error和warn的日志要归档在一个文件中;
info和其余级别的日志归档在一个文件中,并且每小时自动切割日志;
解决办法:
1. 在/etc/rsyslog.d目录下新建配置文件postgresql.conf
vi /etc/rsyslog.d/postgresql.conf
#定义日志存储路径template
$template postgresql_warn,"/data/syslog/%fromhost-ip%/error.log" $template postgresql_info,"/data/syslog/%fromhost-ip%/postgresql.%$year%-%$month%-%$day%-%$hour%"
#定义日志存储格式,只存储msg信息
#Define log format to Postgresql $template pgsql_format, "%msg%\n"
#通过if判断式定义日志收集规则,并应用日志format:
#Postgresql log if ($syslogfacility-text ==‘local0‘ and $syslogpriority-text == ‘warning‘ or $syslogpriority-text == ‘err‘) and $fromhost-ip == ‘10.1.1.11‘ then -?postgre sql_warn;pgsql_format if ($syslogfacility-text ==‘local0‘ and $syslogpriority-text != ‘warning‘ and $syslogpriority-text != ‘err‘) and $fromhost-ip == ‘10.1.1.11‘ then -?postgr esql_info;pgsql_format
2. 重启日志服务
/etc/init.d/rsyslog restart
3.进入指定目录查看收集到的日志
本文出自 “DBQ blog” 博客,谢绝转载!
标签:rsyslog
原文地址:http://naonao.blog.51cto.com/1135983/1544934