[tpm] transparently detecting when a file goes missing

Fulko Hew fulko.hew at gmail.com
Fri Sep 7 07:31:15 PDT 2012


Since the list has been quiet lately, I thought I'd ask the
brilliant minds for a suggestion.


...logging...

[ and yes I know about all the mega-logging frameworks, but ...]

To add simple logging simply, to my app, I decided to close and
reopen STDOUT and STDERR pointing at a log file at the start of my app.
This enables me to simply print and have stuff captured without
having the overhead of a framework.

 close STDOUT; open STDOUT, ">>", "$filename"; STDOUT->autoflush(1);
 ...
 print "log this\n";

This technique works great until someone/something comes along
and (re)moves the log file out from under me (like logrotate).
My logging is still happening, but to the original file, and not
the 'new' (empty) file. Since I never re-open the file,
my information isn't going where I expect it to.

If I open/write/close on every message it would work right,
but then my simple approach of catching prints doesn't.

Is there some magic way to detect this occurrence and auto-reopen
the 'new' file?

[Something like tie'ing to a handle's output functionality and
so it could open/print/close everytime instead.]

TIA
Fulko
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/toronto-pm/attachments/20120907/416461a5/attachment.html>


More information about the toronto-pm mailing list