CINXE.COM
File::Tail - Perl extension for reading from continously updated files - metacpan.org
<!DOCTYPE html> <html lang="en-US"> <head> <title>File::Tail - Perl extension for reading from continously updated files - metacpan.org</title> <link rel="preload" as="fetch" href="/account/login_status" crossorigin="anonymous" /> <link href="/assets/style-XFEQ536G.css" rel="stylesheet" type="text/css"> <script src="/assets/main-WXBSEDQJ.js" type="module"></script> <link rel="alternate" type="application/rss+xml" title="Recent CPAN Uploads of File-Tail - MetaCPAN" href="/dist/File-Tail/releases.rss" /> <link rel="canonical" href="https://metacpan.org/pod/File::Tail" /> <meta name="description" content="Perl extension for reading from continously updated files" /> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=5"> <link rel="shortcut icon" href="/static/icons/favicon.ico"> <link rel="apple-touch-icon" sizes="152x152" href="/static/icons/apple-touch-icon.png"> <link rel="search" href="/static/opensearch.xml" type="application/opensearchdescription+xml" title="MetaCPAN"> <script async src="https://perl-ads.perlhacks.com/perl-ads.js"></script> <script async src="https://www.googletagmanager.com/gtag/js?id=G-E82Q2V8LVD"></script> <meta property="og:site_name" content="MetaCPAN" /> <meta name="twitter:site" content="@metacpan" /> <meta property="og:type" content="article" /> <meta name="twitter:card" content="summary" /> <meta property="og:url" content="https://metacpan.org/pod/File::Tail" /> <meta property="og:title" content="File::Tail" /> <meta property="og:description" content="Perl extension for reading from continously updated files" /> <meta property="og:image" content="https://metacpan.org/static/images/dots.png" /> </head> <body> <nav class="navbar navbar-default" role="navigation"> <div class="header-logo-large hidden-xs"> <a href="/" tabindex="0"> <svg class="logo" aria-label="MetaCPAN"> <use class="logo" href="/static/images/metacpan-logo.svg#logo" /> </svg> </a> </div> <div class="header-logo-icon visible-xs"> <a href="/"> <svg class="logo" aria-label="MetaCPAN"> <use class="logo" href="/static/images/metacpan-logo.svg#dots" /> </svg> </a> </div> <ul class="nav navbar-nav menu-items hidden-xs hidden-sm"> <li><a href="/about">About</a></li> <li><a href="/about/sponsors">Sponsor</a></li> <li><a href="https://grep.metacpan.org/">grep::cpan</a></li> <li><a href="/recent">Recent</a></li> <li><a href="/about/faq">FAQ</a></li> <li><a href="/tools">Tools</a></li> <li><a href="https://fastapi.metacpan.org/">API</a></li> </ul> <ul class="nav navbar-nav navbar-right"> <button type="button" class="searchbar-btn visible-xs visible-sm"> <i class="fa fa-search button-fa-icon"></i> </button> <form action="/search" class="searchbar-form visible-md visible-lg search-form form-horizontal"> <input type="hidden" name="size" id="metacpan_search-size" value="20"> <div class="form-group"> <div class="search-group"> <i class="fa fa-search"></i> <input type="text" name="q" placeholder="Search the CPAN" size="41" autocorrect="off" autocapitalize="off" spellcheck="false" id="metacpan_search-input" class="form-control" value=""> </div> </div> </form> <li class="icon-slidepanel visible-xs visible-sm"> <button data-toggle="slidepanel" data-target=".slidepanel"> <span class="button-fa-icon"> <i class="fa fa-bars slidepanel-open"></i> <i class="fa fa-times slidepanel-close"></i> </span> </button> </li> <li class="dropdown login-dropdown show-logged-in"> <button type="button" class="dropdown-toggle" data-toggle="dropdown"> <i class="fa fa-user button-fa-icon logged-in-icon" aria-hidden="true"></i> <i class="fas fa-chevron-down"></i> </button> <ul class="dropdown-menu"> <li><a href="/account/identities">Identities</a></li> <li><a href="/account/profile">Profile</a></li> <li><a href="/account/favorite/list">Favorites</a></li> <li> <a href="#" type="button" class="logout-button"> Logout </a> </li> </ul> </li> <li class="dropdown login-dropdown show-logged-out"> <button type="button" class="dropdown-toggle" data-toggle="dropdown"> <i class="fa fa-user button-fa-icon avatar-placeholder" aria-hidden="true"></i> <i class="fas fa-chevron-down"></i> </button> <ul class="dropdown-menu"> <li> <a href="/login/github"> <i class="fab fa-github fa-fw"></i> GitHub </a> </li> <li> <a href="/login/twitter"> <i class="fab fa-twitter fa-fw"></i> Twitter </a> </li> <li> <a href="/login/google"> <i class="fab fa-google fa-fw"></i> Google </a> </li> </ul> </li> <li class="dropdown login-dropdown hide-logged-in hide-logged-out"> <button> <i class="fa fa-user button-fa-icon" aria-hidden="true"></i> </button> </li> </ul> </nav> <div class="page-content "> <div id="perl-ad-target" class="top-notify-banner perl-ad-target"> </div> <nav class="sidebar"> <div class="slidepanel"> <ul class="nav-list "> <li class="nav-header no-margin-top"> <div class="ttip" data-toggle="tooltip" data-placement="bottom" title="The date that this version of File-Tail was released."> <span class="relatize">02 Aug 2015 14:23:35 UTC</span> </div> </li> <li> Distribution: <a href="/dist/File-Tail">File-Tail</a> </li> <li> Module version: 1.3 </li> <li> <a data-keyboard-shortcut="g s" href="/dist/File-Tail/source/Tail.pm">Source</a> (<a href="/dist/File-Tail/source/Tail.pm?raw=1">raw</a>) </li> <li> <a data-keyboard-shortcut="g b" href="/dist/File-Tail/source">Browse</a> (<a href="/dist/File-Tail/source?raw=1">raw</a>) </li> <li> <a data-keyboard-shortcut="g c" href="/dist/File-Tail/changes">Changes</a> </li> <li> <a class="nopopup" href="/dist/File-Tail/contribute">How to Contribute</a> </li> <li> <a rel="noopener nofollow" data-keyboard-shortcut="g i" href="https://rt.cpan.org/Public/Dist/Display.html?Name=File-Tail">Issues</a> (22) </li> <li> <a rel="noopener nofollow" href="http://matrix.cpantesters.org/?dist=File-Tail+1.3" title="Matrix">Testers</a> <span title="(pass / fail / na)">(<a rel="noopener nofollow" href="https://www.cpantesters.org/distro/F/File-Tail.html?oncpan=1&distmat=1&version=1.3&grade=2" style="color: #090">735</a> / <a rel="noopener nofollow" href="https://www.cpantesters.org/distro/F/File-Tail.html?oncpan=1&distmat=1&version=1.3&grade=3" style="color: #900">0</a> / <a rel="noopener nofollow" href="https://www.cpantesters.org/distro/F/File-Tail.html?oncpan=1&distmat=1&version=1.3&grade=4">0</a>)</span> </li> <li> <a rel="noopener nofollow" href="http://cpants.cpanauthors.org/release/MGRABNAR/File-Tail-1.3">Kwalitee</a> </li> <li> <div class="ttip" data-toggle="tooltip" data-placement="bottom" title="The # people with an indexing permission on File-Tail who have released something to CPAN in the last 2 years (i.e. the # people likely able to release critical fixes in a timely manner)"> Bus factor: 0 </div> </li> <li> <a rel="noopener nofollow" href="http://cpancover.com/latest/File-Tail-1.3/index.html">57.64% Coverage </a> </li> <li> License: perl_5 </li> <li class="nav-header">Activity</li> <li> <div class="activity-graph"> <img src="/dist/File-Tail/activity.svg?res=month" /> <div class="comment">24 month</div> </div> </li> <li class="nav-header">Tools</li> <li> <a itemprop="downloadUrl" href="https://cpan.metacpan.org/authors/id/M/MG/MGRABNAR/File-Tail-1.3.tar.gz"> Download (<span itemprop="fileSize">23.84KB</span>)</a> </li> <li> <a href="https://explorer.metacpan.org/?url=%2Fmodule%2FMGRABNAR%2FFile-Tail-1.3%2FTail.pm"> MetaCPAN Explorer </a> </li> <li> <a href="/dist/File-Tail/permissions"> Permissions </a> </li> <li> <a href="/dist/File-Tail/releases.rss"> Subscribe to distribution </a> </li> <li> <button class="btn btn-link" data-toggle="modal" data-target="#metacpan_install-instructions-dialog"> Install Instructions </button> </li> <li> <form action="/search"> <input type="hidden" name="q" value="dist:File-Tail"> <input type="search" name="q" placeholder="Search distribution" class="form-control tool-bar-form"> <input type="submit" style="display: none"> </form> </li> <li> <form action="https://grep.metacpan.org/search"> <input type="hidden" name="qd" value="File-Tail"> <input type="hidden" name="source" value="metacpan"> <input type="search" name="q" placeholder="grep distribution" class="form-control tool-bar-form"> <input type="submit" style="display: none"> </form> </li> <li class="version-jump"> <select class="select-navigator form-control tool-bar-form"> <option disabled selected>Jump to version</option> <option disabled value="/release/MGRABNAR/File-Tail-1.3/view/Tail.pm" >1.3 (MGRABNAR on 2015-08-02)</option> <option value="/release/MGRABNAR/File-Tail-1.2/view/Tail.pm" >1.2 (MGRABNAR on 2015-04-21)</option> <option value="/release/MGRABNAR/File-Tail-1.1/view/Tail.pm" >1.1 (MGRABNAR on 2015-04-18)</option> <option value="/release/MGRABNAR/File-Tail-1.0/view/Tail.pm" >1.0 (MGRABNAR on 2014-12-03)</option> <option value="/release/MGRABNAR/File-Tail-0.99.3/view/Tail.pm" >0.99.3 (MGRABNAR on 2005-09-14)</option> <optgroup label="BackPAN">' <option value="/release/MGRABNAR/File-Tail-0.99.2/view/Tail.pm" >0.99.2 (MGRABNAR on 2005-09-14)</option> <option value="/release/MGRABNAR/File-Tail-0.99.1/view/Tail.pm" >0.99.1 (MGRABNAR on 2004-12-01)</option> <option value="/release/MGRABNAR/File-Tail-0.98/view/Tail.pm" >0.98 (MGRABNAR on 2000-12-27)</option> <option value="/release/MGRABNAR/File-Tail-0.97/view/Tail.pm" >0.97 (MGRABNAR on 2000-10-03)</option> <option value="/release/MGRABNAR/File-Tail-0.96/view/Tail.pm" >0.96 (MGRABNAR on 2000-08-14)</option> <option value="/release/MGRABNAR/File-Tail-0.95/view/Tail.pm" >0.95 (MGRABNAR on 1999-12-09)</option> <option value="/release/MGRABNAR/File-Tail-0.94/view/Tail.pm" >0.94 (MGRABNAR on 1999-11-17)</option> <option value="/release/MGRABNAR/File-Tail-0.91/view/Tail.pm" >0.91 (MGRABNAR on 1999-02-02)</option> <option value="/release/MGRABNAR/File-Tail-0.90/view/Tail.pm" >0.90 (MGRABNAR on 1999-01-15)</option> <option value="/release/MGRABNAR/File-Tail-0.85/view/Tail.pm" >0.85 (MGRABNAR on 1998-10-28)</option> <option value="/release/MGRABNAR/File-Tail-0.81/view/Tail.pm" >0.81 (MGRABNAR on 1998-10-15)</option> <option value="/release/MGRABNAR/File-Tail-0.80/view/Tail.pm" >0.80 (MGRABNAR on 1998-10-14)</option> <option value="/release/MGRABNAR/File-Tail-0.70/view/Tail.pm" >0.70 (MGRABNAR on 1998-08-13)</option> <option value="/release/MGRABNAR/File-Tail-0.7/view/Tail.pm" >0.7 (MGRABNAR on 1998-08-13)</option> </optgroup> </select> </li> <li class="version-diff"> <select class="select-navigator form-control tool-bar-form"> <option disabled selected>Diff with version</option> <option disabled value="/release/MGRABNAR/File-Tail-1.3/diff/MGRABNAR/File-Tail-1.3/Tail.pm" >1.3 (MGRABNAR on 2015-08-02)</option> <option value="/release/MGRABNAR/File-Tail-1.3/diff/MGRABNAR/File-Tail-1.2/Tail.pm" >1.2 (MGRABNAR on 2015-04-21)</option> <option value="/release/MGRABNAR/File-Tail-1.3/diff/MGRABNAR/File-Tail-1.1/Tail.pm" >1.1 (MGRABNAR on 2015-04-18)</option> <option value="/release/MGRABNAR/File-Tail-1.3/diff/MGRABNAR/File-Tail-1.0/Tail.pm" >1.0 (MGRABNAR on 2014-12-03)</option> <option value="/release/MGRABNAR/File-Tail-1.3/diff/MGRABNAR/File-Tail-0.99.3/Tail.pm" >0.99.3 (MGRABNAR on 2005-09-14)</option> <optgroup label="BackPAN">' <option value="/release/MGRABNAR/File-Tail-1.3/diff/MGRABNAR/File-Tail-0.99.2/Tail.pm" >0.99.2 (MGRABNAR on 2005-09-14)</option> <option value="/release/MGRABNAR/File-Tail-1.3/diff/MGRABNAR/File-Tail-0.99.1/Tail.pm" >0.99.1 (MGRABNAR on 2004-12-01)</option> <option value="/release/MGRABNAR/File-Tail-1.3/diff/MGRABNAR/File-Tail-0.98/Tail.pm" >0.98 (MGRABNAR on 2000-12-27)</option> <option value="/release/MGRABNAR/File-Tail-1.3/diff/MGRABNAR/File-Tail-0.97/Tail.pm" >0.97 (MGRABNAR on 2000-10-03)</option> <option value="/release/MGRABNAR/File-Tail-1.3/diff/MGRABNAR/File-Tail-0.96/Tail.pm" >0.96 (MGRABNAR on 2000-08-14)</option> <option value="/release/MGRABNAR/File-Tail-1.3/diff/MGRABNAR/File-Tail-0.95/Tail.pm" >0.95 (MGRABNAR on 1999-12-09)</option> <option value="/release/MGRABNAR/File-Tail-1.3/diff/MGRABNAR/File-Tail-0.94/Tail.pm" >0.94 (MGRABNAR on 1999-11-17)</option> <option value="/release/MGRABNAR/File-Tail-1.3/diff/MGRABNAR/File-Tail-0.91/Tail.pm" >0.91 (MGRABNAR on 1999-02-02)</option> <option value="/release/MGRABNAR/File-Tail-1.3/diff/MGRABNAR/File-Tail-0.90/Tail.pm" >0.90 (MGRABNAR on 1999-01-15)</option> <option value="/release/MGRABNAR/File-Tail-1.3/diff/MGRABNAR/File-Tail-0.85/Tail.pm" >0.85 (MGRABNAR on 1998-10-28)</option> <option value="/release/MGRABNAR/File-Tail-1.3/diff/MGRABNAR/File-Tail-0.81/Tail.pm" >0.81 (MGRABNAR on 1998-10-15)</option> <option value="/release/MGRABNAR/File-Tail-1.3/diff/MGRABNAR/File-Tail-0.80/Tail.pm" >0.80 (MGRABNAR on 1998-10-14)</option> <option value="/release/MGRABNAR/File-Tail-1.3/diff/MGRABNAR/File-Tail-0.70/Tail.pm" >0.70 (MGRABNAR on 1998-08-13)</option> <option value="/release/MGRABNAR/File-Tail-1.3/diff/MGRABNAR/File-Tail-0.7/Tail.pm" >0.7 (MGRABNAR on 1998-08-13)</option> </optgroup> </select> </li> <li> <ul class="dependencies"> <li class="nav-header">Dependencies</li> <li><a href="/pod/File::stat" title="File::stat" class="ellipsis">File::stat</a></li> <li><a href="/pod/FileHandle" title="FileHandle" class="ellipsis">FileHandle</a></li> <li><a href="/pod/IO::Seekable" title="IO::Seekable" class="ellipsis">IO::Seekable</a></li> <li><a href="/pod/Time::HiRes" title="Time::HiRes" class="ellipsis">Time::HiRes</a></li> <li><i class="ttip" title="dynamic_config enabled">and possibly others</i></li> <li> <hr> </li> <li> <a href="/module/File::Tail/requires">Reverse dependencies</a> </li> <li> <a href="http://deps.cpantesters.org/?module=File%3A%3ATail">CPAN Testers List</a> </li> <li> <a href="https://cpandeps.grinnz.com/?dist=File-Tail">Dependency graph</a> </li> </ul> </li> <li class="nav-header">Permalinks</li> <li> <a href="/release/MGRABNAR/File-Tail-1.3/view/Tail.pm">This version</a> </li> <li> <a href="/pod/File::Tail">Latest version</a> </li> <li> <div class="plussers"> <div class="nav-header">++ed by:</div> <div> <a class="display-all" href="/author/KEEDI"><img src="https://www.gravatar.com/avatar/95f905a7a4ccc573c711e9d264c0fde8?d=identicon&s=20" title="KEEDI" alt="KEEDI"></a> <a class="display-all" href="/author/PAVELSR"><img src="https://www.gravatar.com/avatar/bdd3233525e2a6ca61bbc05752111c15?d=identicon&s=20" title="PAVELSR" alt="PAVELSR"></a> <a class="display-all" href="/author/JMATES"><img src="https://www.gravatar.com/avatar/06accb84e6519284be3941ff72e429cb?d=identicon&s=20" title="JMATES" alt="JMATES"></a> </div> <!-- Display counts of plussers--> <div> <a href="/dist/File-Tail/plussers">3 PAUSE users</a> </div> <div> 5 non-PAUSE users </div> </div> </li> <li> </li> </ul> </div> </nav> <div class="content-navigation"> <div class="breadcrumbs"> <span> <a data-keyboard-shortcut="g a" rel="author" href="/author/MGRABNAR" class="author-name">Matija Grabnar</a> </span> <span> / </span> <div class="release dist-release status-latest maturity-released"> <span class="dropdown"><b class="caret"></b></span> <select class="select-navigator "> <option selected value="/release/MGRABNAR/File-Tail-1.3/view/Tail.pm" >1.3 (MGRABNAR on 2015-08-02)</option> <option value="/release/MGRABNAR/File-Tail-1.2/view/Tail.pm" >1.2 (MGRABNAR on 2015-04-21)</option> <option value="/release/MGRABNAR/File-Tail-1.1/view/Tail.pm" >1.1 (MGRABNAR on 2015-04-18)</option> <option value="/release/MGRABNAR/File-Tail-1.0/view/Tail.pm" >1.0 (MGRABNAR on 2014-12-03)</option> <option value="/release/MGRABNAR/File-Tail-0.99.3/view/Tail.pm" >0.99.3 (MGRABNAR on 2005-09-14)</option> <optgroup label="BackPAN">' <option value="/release/MGRABNAR/File-Tail-0.99.2/view/Tail.pm" >0.99.2 (MGRABNAR on 2005-09-14)</option> <option value="/release/MGRABNAR/File-Tail-0.99.1/view/Tail.pm" >0.99.1 (MGRABNAR on 2004-12-01)</option> <option value="/release/MGRABNAR/File-Tail-0.98/view/Tail.pm" >0.98 (MGRABNAR on 2000-12-27)</option> <option value="/release/MGRABNAR/File-Tail-0.97/view/Tail.pm" >0.97 (MGRABNAR on 2000-10-03)</option> <option value="/release/MGRABNAR/File-Tail-0.96/view/Tail.pm" >0.96 (MGRABNAR on 2000-08-14)</option> <option value="/release/MGRABNAR/File-Tail-0.95/view/Tail.pm" >0.95 (MGRABNAR on 1999-12-09)</option> <option value="/release/MGRABNAR/File-Tail-0.94/view/Tail.pm" >0.94 (MGRABNAR on 1999-11-17)</option> <option value="/release/MGRABNAR/File-Tail-0.91/view/Tail.pm" >0.91 (MGRABNAR on 1999-02-02)</option> <option value="/release/MGRABNAR/File-Tail-0.90/view/Tail.pm" >0.90 (MGRABNAR on 1999-01-15)</option> <option value="/release/MGRABNAR/File-Tail-0.85/view/Tail.pm" >0.85 (MGRABNAR on 1998-10-28)</option> <option value="/release/MGRABNAR/File-Tail-0.81/view/Tail.pm" >0.81 (MGRABNAR on 1998-10-15)</option> <option value="/release/MGRABNAR/File-Tail-0.80/view/Tail.pm" >0.80 (MGRABNAR on 1998-10-14)</option> <option value="/release/MGRABNAR/File-Tail-0.70/view/Tail.pm" >0.70 (MGRABNAR on 1998-08-13)</option> <option value="/release/MGRABNAR/File-Tail-0.7/view/Tail.pm" >0.7 (MGRABNAR on 1998-08-13)</option> </optgroup> </select> <a data-keyboard-shortcut="g d" class="release-name" href="/dist/File-Tail">File-Tail-1.3</a> </div> <span class="river-gauge-gauge"> <svg width="24px" height="15px" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <g> <title> River stage two • 9 direct dependents • 19 total dependents </title> <rect x="0" y="0" width="4" height="15" fill="#7ea3f2" /> <rect x="5" y="0" width="4" height="15" fill="#7ea3f2" /> <rect x="10" y="0" width="4" height="15" fill="#e4e2e2" /> <rect x="15" y="0" width="4" height="15" fill="#e4e2e2" /> <rect x="20" y="0" width="4" height="15" fill="#e4e2e2" /> </g> </svg> </span> <div id="File-Tail-fav" class="show-logged-in"> <form action="/account/favorite/add" style="display: inline" method="POST"> <input type="hidden" name="remove" value="0"> <input type="hidden" name="release" value="File-Tail-1.3"> <input type="hidden" name="author" value="MGRABNAR"> <input type="hidden" name="distribution" value="File-Tail"> <button type="submit" class="favorite highlight"><span>8</span> ++</button> </form> </div> <div class="show-logged-out"> <button class="fav-not-logged-in favorite highlight"><span>8</span> ++</button> </div> / <span>File::Tail</span> </div> </div> <main class="content"> <nav class="toc"> <div class="toc-header"><strong>Contents</strong></div> <ul> <li><a href="#NAME">NAME</a></li> <li><a href="#SYNOPSIS">SYNOPSIS</a></li> <li><a href="#DESCRIPTION">DESCRIPTION</a></li> <li><a href="#CONSTRUCTOR">CONSTRUCTOR</a> <ul> <li><a href="#new-(%5B-ARGS-%5D)">new ([ ARGS ])</a></li> </ul> </li> <li><a href="#METHODS">METHODS</a> <ul> <li><a href="#read">read</a></li> <li><a href="#select">select</a></li> </ul> </li> <li><a href="#TO-BE-DONE">TO BE DONE</a></li> <li><a href="#AUTHOR">AUTHOR</a></li> <li><a href="#SEE-ALSO">SEE ALSO</a></li> </ul></nav> <div class="pod anchors"> <h1 id="NAME">NAME</h1> <p>File::Tail - Perl extension for reading from continously updated files</p> <h1 id="SYNOPSIS">SYNOPSIS</h1> <pre><code>use File::Tail; $file=File::Tail->new("/some/log/file"); while (defined($line=$file->read)) { print "$line"; } use File::Tail; $file=File::Tail->new(name=>$name, maxinterval=>300, adjustafter=>7); while (defined($line=$file->read)) { print "$line"; }</code></pre> <p>OR, you could use tie (additional parameters can be passed with the name, or can be set using $ref):</p> <pre><code>use File::Tail; my $ref=tie *FH,"File::Tail",(name=>$name); while (<FH>) { print "$_"; }</code></pre> <p>Note that the above script will never exit. If there is nothing being written to the file, it will simply block.</p> <p>You can find more synopsii in the file logwatch, which is included in the distribution.</p> <p>Note: Select functionality was added in version 0.9, and it required some reworking of all routines. ***PLEASE*** let me know if you see anything strange happening.</p> <p>You can find two way of using select in the file select_demo which is included in the ditribution.</p> <h1 id="DESCRIPTION">DESCRIPTION</h1> <p>The primary purpose of File::Tail is reading and analysing log files while they are being written, which is especialy usefull if you are monitoring the logging process with a tool like Tobias Oetiker's MRTG.</p> <p>The module tries very hard NOT to "busy-wait" on a file that has little traffic. Any time it reads new data from the file, it counts the number of new lines, and divides that number by the time that passed since data were last written to the file before that. That is considered the average time before new data will be written. When there is no new data to read, <code>File::Tail</code> sleeps for that number of seconds. Thereafter, the waiting time is recomputed dynamicaly. Note that <code>File::Tail</code> never sleeps for more than the number of seconds set by <code>maxinterval</code>.</p> <p>If the file does not get altered for a while, <code>File::Tail</code> gets suspicious and startschecking if the file was truncated, or moved and recreated. If anything like that had happened, <code>File::Tail</code> will quietly reopen the file, and continue reading. The only way to affect what happens on reopen is by setting the reset_tail parameter (see below). The effect of this is that the scripts need not be aware when the logfiles were rotated, they will just quietly work on.</p> <p>Note that the sleep and time used are from Time::HiRes, so this module should do the right thing even if the time to sleep is less than one second.</p> <p>The logwatch script (also included) demonstrates several ways of calling the methods.</p> <h1 id="CONSTRUCTOR">CONSTRUCTOR</h1> <h2 id="new-([-ARGS-])"><a id="new"></a><a id="new-ARGS"></a>new ([ ARGS ])</h2> <p>Creates a <code>File::Tail</code>. If it has only one paramter, it is assumed to be the filename. If the open fails, the module performs a croak. I am currently looking for a way to set $! and return undef.</p> <p>You can pass several parameters to new:</p> <dl> <dt id="name">name</dt> <dd> <p>This is the name of the file to open. The file will be opened for reading. This must be a regular file, not a pipe or a terminal (i.e. it must be seekable).</p> </dd> <dt id="maxinterval">maxinterval</dt> <dd> <p>The maximum number of seconds (real number) that will be spent sleeping. Default is 60, meaning <code>File::Tail</code> will never spend more than sixty seconds without checking the file.</p> </dd> <dt id="interval">interval</dt> <dd> <p>The initial number of seconds (real number) that will be spent sleeping, before the file is first checked. Default is ten seconds, meaning <code>File::Tail</code> will sleep for 10 seconds and then determine, how many new lines have appeared in the file.</p> </dd> <dt id="adjustafter">adjustafter</dt> <dd> <p>The number of <code>times</code> <code>File::Tail</code> waits for the current interval, before adjusting the interval upwards. The default is 10.</p> </dd> <dt id="resetafter">resetafter</dt> <dd> <p>The number of seconds after last change when <code>File::Tail</code> decides the file may have been closed and reopened. The default is adjustafter*maxinterval.</p> </dd> <dt id="maxbuf">maxbuf</dt> <dd> <p>The maximum size of the internal buffer. When File::Tail suddenly found an enormous ammount of information in the file (for instance if the retry parameters were set to very infrequent checking and the file was rotated), File::Tail sometimes slurped way too much file into memory. This sets the maximum size of File::Tail's buffer.</p> <p>Default value is 16384 (bytes).</p> <p>A large internal buffer may result in worse performance (as well as increased memory usage), since File::Tail will have to do more work processing the internal buffer.</p> </dd> <dt id="nowait">nowait</dt> <dd> <p>Does not block on read, but returns an empty string if there is nothing to read. DO NOT USE THIS unless you know what you are doing. If you are using it in a loop, you probably DON'T know what you are doing. If you want to read tails from multiple files, use select.</p> </dd> <dt id="ignore_nonexistant">ignore_nonexistant</dt> <dd> <pre><code>Do not complain if the file doesn't exist when it is first opened or when it is to be reopened. (File may be reopened after resetafter seconds have passed since last data was found.)</code></pre> </dd> <dt id="tail">tail</dt> <dd> <pre><code>When first started, read and return C<n> lines from the file. If C<n> is zero, start at the end of file. If C<n> is negative, return the whole file. Default is C<0>.</code></pre> </dd> <dt id="reset_tail">reset_tail</dt> <dd> <pre><code> Same as tail, but applies after reset. (i.e. after the file has been automaticaly closed and reopened). Defaults to C<-1>, i.e. does not skip any information present in the file when it first checks it. Why would you want it otherwise? I've seen files which have been cycled like this: grep -v lastmonth log >newlog mv log archive/lastmonth mv newlog log kill -HUP logger </code></pre> <p>Obviously, if this happens and you have reset_tail set to c<-1>, you will suddenly get a whole bunch of lines - lines you already saw. So in this case, reset_tail should probably be set to a small positive number or even <code>0</code>.</p> </dd> <dt id="name_changes">name_changes</dt> <dd> <p>Some logging systems change the name of the file they are writing to, sometimes to include a date, sometimes a sequence number, sometimes other, even more bizarre changes.</p> <p>Instead of trying to implement various clever detection methods, File::Tail will call the code reference defined in name_changes. The code reference should return the string which is the new name of the file to try opening.</p> <p>Note that if the file does not exist, File::Tail will report a fatal error (unless ignore_nonexistant has also been specified).</p> </dd> <dt id="debug">debug</dt> <dd> <p>Set to nonzero if you want to see more about the inner workings of File::Tail. Otherwise not useful.</p> </dd> <dt id="errmode">errmode</dt> <dd> <p>Modeled after the methods from Net:Telnet, here you decide how the errors should be handled. The parameter can be a code reference which is called with the error string as a parameter, an array with a code reference as the first parameter and other parameters to be passed to handler subroutine, or one of the words:</p> <p>return - ignore any error (just put error message in errmsg). warn - output the error message but continue die - display error message and exit</p> <p>Default is die.</p> </dd> </dl> <h1 id="METHODS">METHODS</h1> <h2 id="read">read</h2> <p><code>read</code> returns one line from the input file. If there are no lines ready, it blocks until there are.</p> <h2 id="select">select</h2> <p><code>select</code> is intended to enable the programmer to simoultaneously wait for input on normal filehandles and File::Tail filehandles. Of course, you may use it to simply read from more than one File::Tail filehandle at a time.</p> <p>Basicaly, you call File::Tail::select just as you would normal select, with fields for rbits, wbits and ebits, as well as a timeout, however, you can tack any number of File::Tail objects (not File::Tail filehandles!) to the end.</p> <p>Usage example:</p> <pre><code>foreach (@ARGV) { push(@files,File::Tail->new(name=>"$_",debug=>$debug)); } while (1) { ($nfound,$timeleft,@pending)= File::Tail::select(undef,undef,undef,$timeout,@files); unless ($nfound) { # timeout - do something else here, if you need to } else { foreach (@pending) { print $_->{"input"}." (".localtime(time).") ".$_->read; } } # # There is a more elaborate example in select_demo in the distribution. #</code></pre> <p>When you do this, File::Tail's select emulates normal select, with two exceptions:</p> <p>a) it will return if there is input on any of the parameters (i.e. normal filehandles) _or_ File::Tails.</p> <p>b) In addition to <code>($nfound, $timeleft)</code>, the return array will also contain a list of File::Tail objects which are ready for reading. <code>$nfound</code> will contain the correct number of filehandles to be read (i.e. both normal and File::Tails).</p> <p>Once select returns, when you want to determine which File::Tail objects have input ready, you can either use the list of objects select returned, or you can check each individual object with $object->predict. This returns the ammount of time (in fractional seconds) after which the handle expects input. If it returns 0, there is input waiting. There is no guarantee that there will be input waiting after the returned number of seconds has passed. However, File::Tail won't do any I/O on the file until that time has passed. Note that the value of $timeleft may or may not be correct - that depends on the underlying operating system (and it's select), so you're better off NOT relying on it.</p> <p>Also note, if you are determining which files are ready for input by calling each individual predict, the <code>$nfound</code> value may be invalid, because one or more of File::Tail object may have become ready between the time select has returned and the time when you checked it.</p> <h1 id="TO-BE-DONE"><a id="TO"></a>TO BE DONE</h1> <p>Planned for 1.0: Using $/ instead of \n to separate "lines" (which should make it possible to read wtmp type files). Except that I discovered I have no need for that enhancement If you do, feel free to send me the patches and I'll apply them - if I feel they don't add too much processing time.</p> <h1 id="AUTHOR">AUTHOR</h1> <p>Matija Grabnar, matija.grabnar@arnes.si</p> <h1 id="SEE-ALSO"><a id="SEE"></a>SEE ALSO</h1> <p>perl(1), tail (1), MRTG (http://ee-staff.ethz.ch/~oetiker/webtools/mrtg/mrtg.html)</p></div> <div id="metacpan_install-instructions-dialog" class="modal fade"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h4 class="modal-title">Module Install Instructions</h4> </div> <div class="modal-body"> <p>To install File::Tail, copy and paste the appropriate command in to your terminal.</p> <p><a href="/dist/App-cpanminus/view/bin/cpanm">cpanm</a></p> <pre><code>cpanm File::Tail</code></pre> <p><a href="/pod/CPAN">CPAN shell</a></p> <pre><code>perl -MCPAN -e shell install File::Tail</code></pre> <p>For more information on module installation, please visit <a href="https://www.cpan.org/modules/INSTALL.html">the detailed CPAN module installation guide</a>.</p> </div> <div class="modal-footer"> <a href="#" data-dismiss="modal" class="btn">Close</a> </div> </div> </div> </div> </main> <div class="content-pagination"> </div> </div> <footer class="footer"> <div class="footer-container"> <div class="footer-social"> <div class="footer-link footer-logo"> <a href="/"> <img src="/static/images/metacpan-logo.svg" alt="MetaCPAN" /> </a> </div> <a class="footer-social-link" href="https://github.com/metacpan"> <i class="fab fa-github-square"></i> </a> <a class="footer-social-link" href="https://fosstodon.org/@metacpan"> <i class="fab fa-mastodon"></i> </a> </div> <div class="footer-links"> <div class="footer-link"> <a href="/about">About</a> </div> <div class="footer-link"> <a href="/about/sponsors">Sponsor</a> </div> <div class="footer-link"> <a href="https://grep.metacpan.org">grep::cpan</a> </div> <div class="footer-link"> <a href="/recent">Recent</a> </div> <div class="footer-link"> <a href="/about/faq">FAQ</a> </div> <div class="footer-link"> <a href="/tools">Tools</a> </div> <div class="footer-link"> <a href="https://fastapi.metacpan.org/">API</a> </div> <div class="footer-link"> <a href="https://www.perl.org/">Perl.org</a> </div> </div> <div class="footer-sponsors"> <a class="footer-sponsor-link" target="_blank" href="https://www.bytemark.co.uk/" rel="noopener"> <img class="footer-sponsor-bytemark" src="/static/images/sponsors/bytemark_logo.svg" alt="Bytemark logo"> </a> <a class="footer-sponsor-link" target="_blank" href="https://www.liquidweb.com/" rel="noopener"> <img class="footer-sponsor-liquidweb" src="/static/images/sponsors/liquidweb_logo.png" alt="liquidweb logo"> </a> <a class="footer-sponsor-link" target="_blank" href="https://deriv.com/careers/" rel="noopener"> <img class="footer-sponsor-deriv" src="/static/images/sponsors/deriv.svg" alt="Deriv logo"> </a> <a class="footer-sponsor-link" target="_blank" href="https://geocode.xyz" rel="noopener"> <img class="footer-sponsor-geocode" src="/static/images/sponsors/geocodelogo.svg" alt="Geocode logo"> </a> <a class="footer-sponsor-link" target="_blank" href="https://www.fastly.com/" rel="noopener"> <img class="footer-sponsor-fastly" src="/static/images/sponsors/fastly_logo.svg" alt="Fastly logo"> </a> <a class="footer-sponsor-link" target="_blank" href="https://opencagedata.com" rel="noopener"> <img class="footer-sponsor-opencage" src="/static/images/sponsors/open-cage.svg" alt="OpenCage logo"> </a> <!-- Added 2024-07-22 --> <a class="footer-sponsor-link" target="_blank" href="https://www.elastic.co/" rel="noopener"> <img class="footer-sponsor-elastic" src="/static/images/sponsors/elastic.svg" alt="Elastic logo"> </a> <!-- Added 2024-07-22 --> <a class="footer-sponsor-link" target="_blank" href="https://route4me.com/" rel="noopener"> <img class="footer-sponsor-route4me" src="/static/images/sponsors/route4me.png" alt="Route4Me logo"> </a> </div> </div> </footer> <div class="modal fade" tabindex="-1" role="dialog" id="metacpan_keyboard-shortcuts"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">×</button> <h4 class="modal-title">Keyboard Shortcuts</h4> </div> <div class="modal-body row"> <div class="col-md-6"> <table class="table keyboard-shortcuts"> <thead> <tr> <th></th> <th>Global</th> </tr> </thead> <tbody> <tr> <td class="keys"> <kbd>s</kbd> </td> <td>Focus search bar</td> </tr> <tr> <td class="keys"> <kbd>?</kbd> </td> <td>Bring up this help dialog</td> </tr> </tbody> </table> <table class="table keyboard-shortcuts"> <thead> <tr> <th></th> <th>GitHub</th> </tr> </thead> <tbody> <tr> <td class="keys"> <kbd>g</kbd> <kbd>p</kbd> </td> <td>Go to pull requests</td> </tr> <tr> <td class="keys"> <kbd>g</kbd> <kbd>i</kbd> </td> <td>go to github issues (only if github is preferred repository)</td> </tr> </tbody> </table> </div> <div class="col-md-6"> <table class="table keyboard-shortcuts"> <thead> <tr> <th></th> <th>POD</th> </tr> </thead> <tbody> <tr> <td class="keys"> <kbd>g</kbd> <kbd>a</kbd> </td> <td>Go to author</td> </tr> <tr> <td class="keys"> <kbd>g</kbd> <kbd>c</kbd> </td> <td>Go to changes</td> </tr> <tr> <td class="keys"> <kbd>g</kbd> <kbd>i</kbd> </td> <td>Go to issues</td> </tr> <tr> <td class="keys"> <kbd>g</kbd> <kbd>d</kbd> </td> <td>Go to dist</td> </tr> <tr> <td class="keys"> <kbd>g</kbd> <kbd>r</kbd> </td> <td>Go to repository/SCM</td> </tr> <tr> <td class="keys"> <kbd>g</kbd> <kbd>s</kbd> </td> <td>Go to source</td> </tr> <tr> <td class="keys"> <kbd>g</kbd> <kbd>b</kbd> </td> <td>Go to file browse</td> </tr> </tbody> </table> </div> <div class="col-md-12"> <table class="table keyboard-shortcuts"> <thead> <tr> <th></th> <th>Search terms</th> </tr> </thead> <tbody> <tr> <td><em>module:</em> (e.g. <a href="/search?q=module%3APlugin">module:Plugin</a>)</td> </tr> <tr> <td><em>distribution:</em> (e.g. <a href="/search?q=distribution%3ADancer+auth">distribution:Dancer auth</a>)</td> </tr> <tr> <td><em>author:</em> (e.g. <a href="/search?q=author%3ASONGMU+Redis">author:SONGMU Redis</a>)</td> </tr> <tr> <td><em>version:</em> (e.g. <a href="/search?q=version%3A1.00">version:1.00</a>)</td> </tr> </tbody> </table> </div> </div> <div class="modal-footer"></div> </div> </div> </div> </body> </html>