NAME

AsyncLogWatcher - Perl module for async log watching

SYNOPSIS

use AsyncLogWatcher;

my $watcher = AsyncLogWatcher->new({
  log_file_path    => "/path/to/logfile",
  patterns_file    => "/path/to/patterns",
  exclude_file     => "/path/to/exclude",
  on_match         => sub { print "Matched line: $_[0]\n" },
});

$watcher->watch();

DESCRIPTION

The AsyncLogWatcher module provides functionality for asynchronously watching a log file and applying matching and exclusion patterns to its lines. It can be used to scan logs and perform an action when a matching line is found, ignoring lines that match any of the exclusion patterns.

METHODS

new

my $watcher = AsyncLogWatcher->new({
  log_file_path    => "/path/to/logfile",
  patterns_file    => "/path/to/patterns",
  exclude_file     => "/path/to/exclude",
  on_match         => sub { print "Matched line: $_[0]\n" },
});

Constructs a new AsyncLogWatcher object. Requires the paths to the log file, patterns file, and exclusion file, as well as an optional callback that will be executed when a matching line is found.

load_patterns

$watcher->load_patterns();

Loads the matching patterns from the patterns file. Patterns are loaded as a regular expression.

load_exclude_patterns

$watcher->load_exclude_patterns();

Loads the exclusion patterns from the exclusion file. Patterns are loaded as a regular expression.

is_excluded

my $excluded = $watcher->is_excluded($line);

Checks whether a line matches any of the loaded exclusion patterns. Returns a boolean value.

watch

$watcher->watch();

Starts watching the log file. The method loops indefinitely, checking for new lines in the log file. When a line matches the loaded patterns and does not match any of the exclusion patterns, the provided callback is executed with the line as an argument.

AUTHOR

Kawamura Shingo <pannakoota@gmail.com>

VERSION

Version 0.04

COPYRIGHT AND LICENSE

Copyright (C) 2023 Your Name

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