View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Vyacheslav Matyukhin > Log-Unrotate-1.27 > Log::Unrotate



Annotate this POD


New  1
Open  0
View/Report Bugs
Module Version: 1.27   Source   Latest Release: Log-Unrotate-1.32


Log::Unrotate - Reader of rotated logs.


version 1.27


  use Log::Unrotate;

  my $reader = Log::Unrotate->new({
      log => 'xxx.log',
      pos => 'xxx.pos',

  my $position = $reader->position();
  $reader->commit($position); # rollback the last 2 reads
  my $lag = $reader->lag();


The Log::Unrotate is a class that implements incremental and transparent reading of a log file which correctly handles logrotates.

It tries really hard to never skip any data from logs. If it's not sure about what to do, it fails, and you should either fix your position file manually, or remove it completely.



Creates new unrotate object.


Name of file to store log reading position. Will be created automatically if missing.

Value '-' means not use position file. I.e., pretend it doesn't exist at start and ignore commit calls.


Instead of pos file, you can specify any custom cursor. See Log::Unrotate::Cursor for cursor API details.


Recreate cursor if it's broken.

Warning will be printed. This option is dangerous and shouldn't be enabled light-heartedly.


Name of log file. Value '-' means standard input stream.


Describes behavior when position file doesn't exist. Allowed values: begin (default), end, first.

  • When start is begin, we'll read current log from beginning.
  • When start is end, we'll put current position in log at the end (useful for big files when some new script don't need to read everything).
  • When start is first, Log::Unrotate will find oldest log file and read everything.

Describes behavior when the log is asynchronously appended while read. Allowed values: fixed (default), future.

  • When end is fixed, the log is read up to the position it had when the reader object was created.
  • When end is future, it allows reading the part of the log that was appended after the reader creation (useful for reading from stdin).

Describes locking behaviour. Allowed values: none (default), blocking, nonblocking.

  • When lock is blocking, lock named pos.lock will be acquired in blocking mode.
  • When lock is nonblocking, lock named pos.lock will be acquired in nonblocking mode; if lock file is already locked, exception will be thrown.

This flag is disabled by default.

It enables inode checks when detecting log rotations. This option should not be enabled when retrieving logs via rsync or some other way which modifies inodes.


This flag is set by default. It enables content checks when detecting log rotations. There is actually no reason to disable this option.


Read a string from the file log.


Get your current position in log as an object passible to commit.


Save current position in the file pos. You can also save some other position, previosly taken with position.

Position file gets commited using temporary file, so it'll not be lost if disk space is depleted.


Get the lag between current position and the end of the log in bytes.


Get current log number.


Get current log name. Doesn't contain .N postfix even if cursor points to old log file.


To find and open correct log is a race-condition-prone task.

This module was used in production environment for 3 years, and many bugs were found and fixed. The only known case when position file can become broken is when logrotate is invoked twice in *very* short amount of time, which should never be a case.

Don't set check_inode option on virtual hosts, especially on openvz-based ones. When host migrates, inodes of files will change and your position file will become broken.

The logrotate config should not use the "compress" option to make that module function properly. If you need to compress logs, set "delaycompress" option too.


Andrei Mishchenko, Vyacheslav Matjukhin


File::LogReader - another implementation of the same idea.

unrotate(1) - console script to unrotate logs.


Copyright (c) 2006-2010 Yandex LTD. All rights reserved.

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

See <>

syntax highlighting: