From: Mike Buland <xagafinelle@gmail.com>
To: supervision@list.skarnet.org
Subject: Re: [magic sv logging]
Date: Fri, 21 Sep 2012 09:32:43 -0600 [thread overview]
Message-ID: <CAK2oqq+=i2yp+UrKmf63UXq2bEUjWZibOBdkkhj_unVSnOot7Q@mail.gmail.com> (raw)
In-Reply-To: <k3i15f$ie4$1@ger.gmane.org>
[-- Attachment #1: Type: text/plain, Size: 1657 bytes --]
You haven't missed anything, well, it's more like "tail --follow=name
<file>' but instead of piping the output of tail into another program for
processing, this just does all the work in python. Not only was it fun to
write, but I like the fact that I don't need to chain more programs
together.
--Mike
On Fri, Sep 21, 2012 at 9:29 AM, Lorenzo Beretta <lory.fulgi@infinito.it>wrote:
> On 21/09/2012 04:25, Mike Buland wrote:
>
>> I took a different approach and monitored the log output of svlogd, since
>> I
>> wanted the logs anyway. This is some code that well help you with that,
>> anyway:
>>
>> import os
>> import time
>> import stat
>>
>> fIn = open("current", "r")
>> sid = os.stat("current")[stat.ST_**INO]
>>
>> while True:
>> try:
>> sidNew = os.stat("current")[stat.ST_**INO]
>> if sidNew != sid:
>> fIn.close()
>> fIn = open("current", "r")
>> sid = sidNew
>> except:
>> time.sleep( 1 )
>> continue
>>
>> while True:
>> l = fIn.readline()
>> if l is None or l == '':
>> break
>> # do something interesting with your line here
>> time.sleep( 1 )
>>
>> This will read everything from current, and when current moves, it will
>> read what's left, open the new current, and read all of it. I use it to
>> monitor apache log output, and it hasn't failed me yet.
>>
>> --Mike
>>
>
> Unless I missed something, it looks as if you're reimplementing the '-F'
> flag in tail :)
>
>
>
next prev parent reply other threads:[~2012-09-21 15:32 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-20 23:35 Sergiusz Pawlowicz
2012-09-21 2:25 ` Mike Buland
2012-09-21 15:29 ` Lorenzo Beretta
2012-09-21 15:32 ` Mike Buland [this message]
2012-09-21 15:35 ` Jason Dusek
2012-09-21 15:38 ` Mike Buland
2012-09-22 4:18 ` Laurent Bercot
2012-09-22 5:58 ` Jason Dusek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAK2oqq+=i2yp+UrKmf63UXq2bEUjWZibOBdkkhj_unVSnOot7Q@mail.gmail.com' \
--to=xagafinelle@gmail.com \
--cc=supervision@list.skarnet.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).