NAME

File::Tail::Scribe - Monitor and send the tail of files to a Scribe logging system.

SYNOPSIS

  use File::Tail::Scribe;

  my $log = File::Tail::Scribe->new(
    directories => $args{dirs},
    msg_filter => sub {
        my ($self, $filename, $line) = @_;
        return ('info', 'httpd', "$filename\t$line");
        },
    );

  $log->watch_files();

DESCRIPTION

Basically this module connects File::Tail::Dir to Log::Dispatch::Scribe.

It monitors files in a given directory (or set of directories), such as Apache log files in /var/log/httpd, and as the log files are written to, takes the changes and sends them to a running instance of the Scribe logging system.

PREREQUISITES

The Scribe and Thrift Perl modules from their respective source distributions are required and not available as CPAN dependencies. Further information is available here: <http://notes.jschutz.net/109/perl/perl-client-for-facebooks-scribe-logging-software>

CONSTRUCTOR

new

  $tailer = File::Tail::Scribe->new(%options);

Creates a new instance. Options are:

  • directories, filter, exclude, follow_symlinks, sleep_interval, statefilename, no_init, max_age

    See the equivalent options in File::Tail::Dir: "directories" in File::Tail::Dir, "filter" in File::Tail::Dir, "exclude" in File::Tail::Dir, "follow_symlinks" in File::Tail::Dir, "sleep_interval" in File::Tail::Dir, "statefilename" in File::Tail::Dir, "no_init" in File::Tail::Dir, "max_age" in File::Tail::Dir.

  • scribe_options

    This is a hash containing all of the options to pass to <Log::Dispatch::Scribe/new>.

  • msg_filter

    An optional coderef that can be used to preprocess messages before they are sent to Scribe. The code is passed ($self, $filename, $line), i.e. the File::Tail::Scribe instance, the filename of the file that changed, and the line of text that was added. It must return ($level, $category, $message), i.e. the log level (info, debug etc), the Scribe category, and the log line that will be sent to Scribe. An example:

      msg_filter => sub {
        my $self = shift;
        my $filename = shift;
        my $line = shift;
        $filename =~ s{^.*/}{};                   # remove leading dirs
        $filename =~ s{\.[^.]*$}{};               # remove extension
        $filename ||= 'default';                  # in case everything gets removed
    
        return ('info', 'httpd', "$filename\t$line");
      };

    If no msg_filter is provided, the log level is given by default_level, the category is the filename after removing leading paths and filename extensions, and the message is the log line as given.

  • default_level

    Default logging level. May be set to any valid Log::Dispatch level (debug, info, notice, warning, error, critical, alert, emergency). Defaults to 'info'.

METHODS

File::Tail::Scribe provides the same methods as File::Tail::Dir, plus the following:

SEE ALSO

AUTHOR

Jon Schutz, <jon at jschutz.net> http://notes.jschutz.net

BUGS

Please report any bugs or feature requests to bug-file-tail-scribe at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=File-Tail-Scribe. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc File::Tail::Scribe

You can also look for information at:

ACKNOWLEDGEMENTS

COPYRIGHT & LICENSE

Copyright 2010 Jon Schutz, all rights reserved.

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