0

I'm a newbie to Logwatch and have it set up to watch log files created by celery, a distributed task queue popular in the Python world.

My logwatch.conf "Range" is set to "between yesterday 4am and today 4am” and this range filter works for other log files -- but it's not working for my celery log files.

This is my setup:

/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/scripts/services/celery

#!/bin/bash
cat

It seems the problem is the just using cat as the filter -- obviously that is not filtering any date, just passing through the lines of the celerry log files.

I know logwatch has some built-in date format filters, but I'm not clear how to apply them, nor whether any of them fit the format of celery logs, which look like this:

[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]

My question is: how do I configure logwatch to correctly date-filter these log files?

1 Answer 1

2
+50

I think /usr/share/logwatch/scripts/shared/applyhttpdate file would be helpful.

Define the date format for celery.

/etc/logwatch/scripts/shared/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;
   }
}

And, link the log file to the date format.

/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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .