The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

File::Tail::Lite - Perl module for seekable 'tailf' implementation

SYNOPSIS

Simple usage.

  use File::Tail::Lite;
  my $tailf = new File::Tail::Lite(filename => "/some_path/filename_for_tailf");
  while(my $line) = $tailf->readline())
  {
    print $line;
  }

Get position everytime, so we will not miss any content when crash happens.

  use File::Tail::Lite;
  my $tailf = new File::Tail::Lite(filename => "/some_path/filename_for_tailf");
  while(my ($pos, $line) = $tailf->readline())
  {
    print "[$pos,$line]";
  }

Seek to a position when start reading.

  use File::Tail::Lite;
  my $seekpos = sub_recover_pos();

  my $tailf = new File::Tail::Lite(filename => "/some_path/filename_for_tailf", seekpos => $seekpos);
  while(my ($pos, $line) = $tailf->readline())
  {
    print "[$pos,$line]";
    $seekpos = $pos;
    sub_save_pos($seekpos);
  }

Note that the above scripts will never exit. If there is nothing being written to the file, it will simply block.

DESCRIPTION

This module is made for seekable 'tailf' implementation.

File::Tail is good, but it can not seek when reading started,so we may miss contents if programe crash.

This module slove the problem.

And it is quite simple and easy to use.

METHOD

$file_tail_lite->readline()

return one line one time, blocks until that.

also return $self->{maxbuff} bytes if the line is too long to handle.

$file_tail_lite->{error}

0 : no error.

1 : error happened.

$file_tail_lite->{errinfo}

A string desc the error.

This will be set when $self->{error} == 1.

CONSTRUCTOR

new ([ ARGS])

filename

The name of the file want to tailf.

seekpos

default: 'eof'.

int - start reading from the specified offset

'begin' - read from the head of the file.

'eof' - read the new append contents only.

maxbuf

default: 1024.

readline() returns a line by default.

set the max line length here, so that readline() can break long line.

EXAMPLE

  use File::Tail::Lite;
  use Storable qw(retrieve store);

  my $stor_file = '/tmp/seekpos.tmp';
  my $seekpos = retrieve($stor_file) || 'end';

  my $tailf = new File::Tail::Lite(filename => "/var/log/httpd/access.log", seekpos => $seekpos, maxbuf => 100);
  while(my ($pos, $line) = $tailf->readline())
  {
    print "[$pos,$line]";
    store \$pos, $stor_file;
  }
             

AUTHOR

Written by Chen Gang

yikuyiku.com@gmail.com

http://blog.yikuyiku.com/

COPYRIGHT

Copyright (c) 2014 Chen Gang.

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

SEE ALSO

File::Tail