NAME
LogFilter - A simple log filtering module
SYNOPSIS
use LogFilter;
my $filter = LogFilter->new($keywords_file, $exclude_file, $log_file, $interval);
$filter->filter;
DESCRIPTION
The LogFilter module provides an easy way to filter logs based on keywords and exclude words. It continuously reads a log file and prints lines that contain any of the provided keywords but do not contain any of the provided exclude words.
INSTALLATION
You can install this module:
git clone https://github.com/kawamurashingo/LogFilter.git
perl Makefile.PL
make
make test
make install
METHODS
- new
-
Creates a new LogFilter object.
my $filter = LogFilter->new($keywords_file, $exclude_file, $log_file, $interval);
Arguments:
-
$keywords_file
: a file containing keywords, one per line. -$exclude_file
: a file containing words to exclude, one per line. -$log_file
: the log file to read. -$interval
: the interval at which to read the log file, in seconds. - filter
-
Starts filtering the log file.
$filter->filter;
This method will keep running until the program is terminated.
EXAMPLE
Here is an example of how you might use this module:
#!/usr/bin/perl
use strict;
use warnings;
use LogFilter;
my $keywords_file = '/path/to/keywords.txt';
my $exclude_file = '/path/to/exclude.txt';
my $log_file = '/path/to/my.log';
my $interval = 1; # seconds
my $filter = LogFilter->new($keywords_file, $exclude_file, $log_file, $interval);
$filter->filter;
This script will now continuously print lines from my.log
that contain any of the keywords in keywords.txt
, but do not contain any of the words in exclude.txt
.
The keywords.txt
and exclude.txt
files should contain one word per line. For example:
# keywords.txt
error
warning
failed
# exclude.txt
foobar
This will print lines that contain "error", "warning", or "failed", unless the line also contains "foobar".
SEE ALSO
AUTHOR
Kawamura Shingo <pannakoota@gmail.com>
LICENSE
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.