如何获得logging在芹菜日志过滤date?

我是Logwatch的新手,并且设置它来监视由Python世界中stream行的分布式任务队列celery创build的日志文件。

我的logwatch.conf“范围”被设置为“昨天凌晨4点到今天凌晨4点之间”,这个范围filter适用于其他日志文件 – 但它不适用于我的芹菜日志文件。

这是我的设置:

/etc/logwatch/conf/services/celery.conf

Title = "Celery worker errors" LogFile = celery 

/etc/logwatch/conf/logfiles/celery.conf

 LogFile = /var/log/208-celery.log LogFile = /var/log/234-celery.log LogFile = /var/log/403-celery.log LogFile = /var/log/dev-celery.log 

在/ etc / logwatch /脚本/服务/芹菜

 #!/bin/bash cat 

看起来问题就在于使用cat作为filter – 显然不是过滤任何date,只是通过celerry日志文件的行。

我知道logwatch有一些内置的date格式filter,但我不清楚如何应用它们,也不知道它们中的任何一个是否适合芹菜日志的格式,如下所示:

 [2016-04-26 11:59:37,851: WARNING/MainProcess] celery@big-dog ready. [2016-04-26 11:59:37,852: DEBUG/MainProcess] | Worker: Hub.register Pool... [2016-04-26 11:59:37,852: DEBUG/MainProcess] basic.qos: prefetch_count->16 [2016-04-26 11:59:43,146: INFO/MainProcess] Received task: hello_world[b29ef98a-d9fb-4cc6-b7db-9434a9bcc1e2] 

我的问题是:我如何configurationlogwatch正确的date – 过滤这些日志文件?

我认为/ usr / share / logwatch / scripts / shared / applyhttpdate文件会有帮助。

定义芹菜的date格式。

的/ etc / logwatch /脚本/共享/ applycelerydate

 use Logwatch ':dates'; $Debug = $ENV{'LOGWATCH_DEBUG'} || 0; $SearchDate = TimeFilter('%Y-%m-%d %H:%M:%S'); if ( $Debug > 5 ) { print STDERR "DEBUG: Inside ApplyCeleryDate...\n"; print STDERR "DEBUG: Looking For: " . $SearchDate . "\n"; } while (defined($ThisLine = <STDIN>)) { if ($ThisLine =~ m/\[$SearchDate/o) { print $ThisLine; } } 

然后,将日志文件链接到date格式。

/etc/logwatch/conf/logfiles/celery.conf

 LogFile = /var/log/208-celery.log LogFile = /var/log/234-celery.log LogFile = /var/log/403-celery.log LogFile = /var/log/dev-celery.log *ApplyCeleryDate