Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: View content of Log::Log4perl log file while logger is running

by Tanktalus (Canon)
on Dec 10, 2013 at 17:34 UTC ( #1066477=note: print w/replies, xml ) Need Help??

in reply to View content of Log::Log4perl log file while logger is running

I expect this is simply because the file is opened, and there is no end-of-file reached yet, so the webserver keeps looking for the rest of the input until end-of-file. I'm not sure if eof is signaled or not in this case, so this is all theory.

You may need to write your own "tail -f" replacement for your webserver, grabbing everything that's in the file currently from a beginning index (first time through this will be zero), to the last byte (*), and send it back with the index of the end. Then repeated requests from the browser can ask for the same log file with the new index, receive the new data (if any) and append it to the data in the browser.

(*) This byte issue could haunt you if you write any multi-byte characters to the log file. However, given your use of autoflush and %n, this is unlikely to be an issue. One workaround is to have your server-side process only read up to \n's, and not return the last line unless it includes the \n in it. Then you can be assured you're sending full lines back to the browser. If you're using ISO-88591 characters only, or at least a single-byte encoding and language, then this is moot. I just have to worry about Chinese, Japanese, etc., characters showing up in my logs, so I pay attention to this.

  • Comment on Re: View content of Log::Log4perl log file while logger is running

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1066477]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2017-11-22 04:42 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (315 votes). Check out past polls.