I'm setting up a virtual hosting environment with mod_vhost_alias, so I've got to manually split up log files for each client. I figured that would be really simple, and discovered that it was. All I had to do was write a script that takes input on STDIN and have it do what I need to. The Apache group has split-logfiles which theoretically does this. But I'm running into a peculiar problem. When I put it into my Apache log files with:
CustomLog "|/opt/apache/logs/split-logfiles" combined
It opens each file that it is supposed to, but then none of the log entries get written. I decided to do some testing of my own and wrote this:
#!/usr/bin/perl $isopen = 0; while ($log_line = <STDIN>) { $myfile = "/var/tmp/test.log"; unless($isopen and -f $myfile) { open MYHAPPYFILE, ">$myfile" or die "Error opening $myfile"; $isopen = 1; } printf MYHAPPYFILE "%s", $log_line; } exit 0;
And when I put that into apache instead of split-logfiles, it does the same thing: /var/tmp/test.log gets created but none of the log entries get put into it. When I tried printing to STDERR instead of MYHAPPYFILE, it showed up fine in the error log. Any ideas?

In reply to Apache log pipe doesn't write to log files by SamQi

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.