Logfile::Tail and logfile-tail

Logfile::Tail - read log files

SYNOPSIS

    use Logfile::Tail ();
    my $file = new Logfile::Tail('/var/log/messages');
    while (<$file>) {
            # process the line
    }

and later in different process

    my $file = new Logfile::Tail('/var/log/messages');

and continue reading where we've left out the last time. Also possible is to explicitly save the current position:

    my $file = new Logfile::Tail('/var/log/messages',
            { autocommit => 0 });
    my $line = $file->getline();
    $file->commit();

DESCRIPTION

Log files are files that are generated by various running programs. They are generally only appended to. When parsing information from log files, it is important to only read each record / line once, both for performance and for accounting and statistics reasons.

The Logfile::Tail provides an easy way to achieve the read-just-once processing of log files.

The module remembers for each file the position where it left out the last time, in external status file, and upon next invocation it seeks to the remembered position. It also stores checksum of 512 bytes before that position, and if the checksum does not match the file content the next time it is read, it will try to find the rotated file and read the end of it before advancing to newer rotated file or to the current log file.

Both .num and -date suffixed rotated files are supported.

METHODS

AUTHOR AND LICENSE

Copyright (c) 2010--2012 Jan Pazdziora.

Logfile::Tail is free software. You can redistribute it and/or modify it under the terms of either:

a) the GNU General Public License, version 2 or 3;

b) the Artistic License, either the original or version 2.0.

logfile-tail - output (cat) file from the last saved position

SYNOPSIS

logfile-tail [ --status=status-directory | --status=status-file ] logfile
logfile-tail --help

DESCRIPTION

When processing log files, you want to continue reading where you left out the last time. The logfile-tail program uses the Logfile::Tail module internally to store the position last seen for the log file and retrieve it upon the subsequent invocation.

The program also handles rotated files -- if the log file was rotated since the last read, it is detected and the rest of the rotated file is read first, before proceeding to the newer rotate file or to the current log file.

The content is printed to the standard output.

OPTIONS

EXAMPLES

# output data from Apache's access_log
logfile-tail /var/log/httpd/access_log

logfile-tail --status /var/run/apache/logfile-tail error_log

AUTHOR

Copyright (C) 2011--2012 by Jan Pazdziora

LICENSE

This module is free software. You can redistribute it and/or modify it under the terms of the Artistic License 2.0.

This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose.