Top-rated recipes tagged "tail"http://code.activestate.com/recipes/tags/tail/top/2015-06-06T12:13:00-07:00ActiveState Code RecipesLog watcher (tail -F *.log) (Python)
2014-04-04T15:54:03-07:00Giampaolo RodolĂ http://code.activestate.com/recipes/users/4178764/http://code.activestate.com/recipes/577968-log-watcher-tail-f-log/
<p style="color: grey">
Python
recipe 577968
by <a href="/recipes/users/4178764/">Giampaolo RodolĂ </a>
(<a href="/recipes/tags/color/">color</a>, <a href="/recipes/tags/log/">log</a>, <a href="/recipes/tags/logging/">logging</a>, <a href="/recipes/tags/monitor/">monitor</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/rotate/">rotate</a>, <a href="/recipes/tags/rotations/">rotations</a>, <a href="/recipes/tags/tail/">tail</a>).
Revision 10.
</p>
<p>A python class which "watches" a directory and calls a callback(filename, lines) function every time one of the files being watched gets written, in real time.</p>
<p>Practically speaking, this can be compared to <em>"tail -F *.log"</em> UNIX command, but instead of having lines printed to stdout a python function gets called.</p>
<p>Similarly to tail, it takes care of "watching" new files which are created after initialization and "unwatching" those ones which are removed in the meantime. This means you'll be able to "follow" and support also rotating log files.</p>
<p><strong>History</strong></p>
<ul>
<li>rev5 (2013-04-05):
<ul>
<li>sizehint parameter</li>
</ul></li>
<li>rev4 (2013-03-16):
<ul>
<li>python 3 support (also dropped support for python <= 2.5)</li>
<li>windows support</li>
<li>unit tests</li>
<li>main class can also be used as a context manager</li>
</ul></li>
<li>rev3 (2012-01-13): initial release</li>
</ul>
Tail a continuously growing file (like tail -f filename) (Python)
2011-05-20T16:32:59-07:00Jason Morrisshttp://code.activestate.com/recipes/users/4174039/http://code.activestate.com/recipes/577710-tail-a-continuously-growing-file-like-tail-f-filen/
<p style="color: grey">
Python
recipe 577710
by <a href="/recipes/users/4174039/">Jason Morriss</a>
(<a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/rotate/">rotate</a>, <a href="/recipes/tags/tail/">tail</a>).
</p>
<p>This is my version of a "File Tail" class for Python3 (will not work on Python2 w/o a couple of modifications). My original inspiration came from the perl File::Tail module.</p>
<p>Transparently handles files that get rotated or truncated. </p>
<ul>
<li>Does not take 100% CPU. </li>
<li>Does not take up much memory.</li>
<li>Is capable of handling any size log file.</li>
<li><em>Not tested on Windows</em></li>
</ul>
<p>Example:</p>
<pre class="prettyprint"><code>from filetail import FileTail
tail = FileTail("/var/log/syslog")
for line in tail:
print(line, end="")
</code></pre>
Tail multiple pidgin IRC logfiles (Python)
2015-06-06T12:13:00-07:00Anton Vredegoorhttp://code.activestate.com/recipes/users/2667360/http://code.activestate.com/recipes/579066-tail-multiple-pidgin-irc-logfiles/
<p style="color: grey">
Python
recipe 579066
by <a href="/recipes/users/2667360/">Anton Vredegoor</a>
(<a href="/recipes/tags/colorize/">colorize</a>, <a href="/recipes/tags/irc/">irc</a>, <a href="/recipes/tags/iterators/">iterators</a>, <a href="/recipes/tags/logfiles/">logfiles</a>, <a href="/recipes/tags/merging/">merging</a>, <a href="/recipes/tags/nonblocking/">nonblocking</a>, <a href="/recipes/tags/pidgin/">pidgin</a>, <a href="/recipes/tags/tail/">tail</a>, <a href="/recipes/tags/threads/">threads</a>).
Revision 2.
</p>
<p>Tail multiple pidgin IRC logfiles. </p>
<p>Pidgin should be connected to IRC with the channels one
wants to tail joined, and it should save logs as text.</p>
<p>The script needs two arguments:</p>
<pre class="prettyprint"><code>the directory containing the directories with channel logs
a list of channel names, quoted and separated by spaces
</code></pre>
<p>Example command:</p>
<p>python pidgin-irctail.py
-d <a href="mailto:~/.purple/logs/irc/YOUR_IRC_HANDLE@irc.freenode.net">~/.purple/logs/irc/YOUR_IRC_HANDLE@irc.freenode.net</a>
-c "#chan1 #chan2 #chan3"</p>
<p>Some text elements are higlighted, and channel names are
inserted into the log lines after the time info.</p>
<p>If more than one channel is entered, the output of the logs
is merged. </p>
Unix tail -n analog (Batch)
2013-10-12T17:35:59-07:00greg zakharovhttp://code.activestate.com/recipes/users/4184115/http://code.activestate.com/recipes/578311-unix-tail-n-analog/
<p style="color: grey">
Batch
recipe 578311
by <a href="/recipes/users/4184115/">greg zakharov</a>
(<a href="/recipes/tags/tail/">tail</a>).
Revision 4.
</p>
<p>Sometime it need to access last n strings in text file, right? Of course you can use third party tools for this purpose (such as tail from Win 2k3 Resource Kit) but how about to create it by yourself? For example:</p>
"tail -f" with inode monitor (Python)
2010-09-21T07:37:38-07:00Denis Barmenkovhttp://code.activestate.com/recipes/users/57155/http://code.activestate.com/recipes/577398-tail-f-with-inode-monitor/
<p style="color: grey">
Python
recipe 577398
by <a href="/recipes/users/57155/">Denis Barmenkov</a>
(<a href="/recipes/tags/inode/">inode</a>, <a href="/recipes/tags/monitor/">monitor</a>, <a href="/recipes/tags/tail/">tail</a>).
Revision 3.
</p>
<p>Sometimes tail -f launched for log file miss the point when program recreates log file.
Script in this recipe monitors inode changes for specified file and restarts tail if needed.</p>
tgraph - Simple ASCII graphing utility (Python)
2011-07-28T21:13:23-07:00Drew Gulinohttp://code.activestate.com/recipes/users/4119417/http://code.activestate.com/recipes/577077-tgraph-simple-ascii-graphing-utility/
<p style="color: grey">
Python
recipe 577077
by <a href="/recipes/users/4119417/">Drew Gulino</a>
(<a href="/recipes/tags/ascii/">ascii</a>, <a href="/recipes/tags/graph/">graph</a>, <a href="/recipes/tags/log/">log</a>, <a href="/recipes/tags/sysadmin/">sysadmin</a>, <a href="/recipes/tags/tail/">tail</a>, <a href="/recipes/tags/unix/">unix</a>).
</p>
<p>Takes a stream of numbers and outputs simple ASCII graphs of those numbers</p>