Hey monks,

I was just presented with a very interesting problem that I think Perl might be able to solve, but I'm not 100% sure how to do it.

We have several processes on our production web application servers that spew to stdout. Currently we have stdout being redirected by our startup scripts for these processes to log files that when something goes wrong with the applications that run on top of these processes the developers review for errors.

The problem with this situation is two-fold.

  1. There is no time within a 24 hour period that the procesees can be restarted. Since the applications that run on top of these processes are involved directly with patient care their production periods are literally 24 hours a day. For that reason logrotate and friends won't work.
  2. The amount of spew these processes issue is on the order of several gig a day. The method that the developers use to access these logs is through a SAMBA share which gets bodgey when the logs get too large.
What I'm hoping to implement is some sort of filter that intercepts the stdout, occasionally closing the file handle (without losing the input stream) for the log file and moving it out of the way.

What schemes have others used to be able to rotate logs? Am I making this too complicated and is it as simple as:

#!/usr/bin/perl -w use strict; # starting psuedo-code while(my $line=<>){ print LOG $line; if file is too big... close LOG rename file open LOG } }
or should I be thinking of other stuff besides?


Peter L. Berghold -- Unix Professional
Peter at Berghold dot Net
   Dog trainer, dog agility exhibitor, brewer of fine Belgian style ales. Happiness is a warm, tired, contented dog curled up at your side and a good Belgian ale in your chalice.

In reply to Log rotating filter. by blue_cowdawg

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.