NAME

AsyncLogWatcher - Asynchronously watches log files for specific patterns

VERSION

Version 0.01

SYNOPSIS

use AsyncLogWatcher;

my $watcher = AsyncLogWatcher->new({
    log_file => '/path/to/log',
    patterns_file => '/path/to/patterns',
    on_match => sub {
        my ($line) = @_;
        print "Matched line: $line\n";
    },
});

my $guard = $watcher->watch;  # Continues to watch until $guard goes out of scope

DESCRIPTION

The AsyncLogWatcher module provides a way to asynchronously watch a log file and perform actions when specific patterns are matched. The module uses AnyEvent for asynchronous processing and File::Tail for continuous log file reading.

METHODS

new

Creates a new instance of AsyncLogWatcher. It accepts a hashref with the following keys:

  • log_file: The log file to watch.

  • patterns_file: A file containing patterns to match. Each pattern should be on a new line in the file.

  • on_match: A callback to be executed when a line in the log file matches a pattern. The matched line is passed to the callback.

watch

Starts watching the log file for matches against the given patterns. It returns a guard object. As long as the guard is in scope, the watcher will continue watching the log file.

AUTHOR

Kawamura Shingo, <pannakoota@gmail.com>

LICENSE AND COPYRIGHT

Copyright 2023 Kawamura Shingo.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.