Forum Moderators: open
Or is it just me? :)
I'm afraid I'm frequently guilty of this. I have a dual-monitor setup at work, and one screen frequently has several windows showing the live logs of various webservers.
Interesting to watch, and I sometimes go as far as to filter it to show only web page requests, and then follow visitors progress live through the website. Useful to watch when you've added a special offer to the homepage, and just for gauging surfers' habits.
Of course, playing with Apache directives like LogFormat, CustomLog, and SetEnvIf makes things more interesting. It's really easy to get Apache to filter out some of the stuff you don't really want to see anyway. There's always seems to be some time when you think "tch, I wish I had the old log file right now", though. The simplest solution is just to have Apache log to both files, so you can pick which one is more appropriate. 'Course I do find it a pain having to su, edit the log file, and restart every time I want to make a small change though... well, I used to, but I figured it would make it simpler to just set up Apache to pipe logs to shell script that filters stuff out. No need for root then. Just a couple more entires in httpd.conf, maybe another environment variable somewhere so I can get to the right log file on each server, and the script itself. But that's it! I'm definitely satisfied now. Although this script is getting a bit long, things keep popping up that I want to filter out, so maybe it would be better to rewrite it in Perl. Silly to use shell in the first place really, Perl was the obvious choice anyway. Shouldn't take long to convert it... But maybe I should get that javascript working in IE properly first, it must be something simple. All I want to do is have the browser scroll to the bottom of the screen automatically, so my PHP script can keep feeding it lines from the log file it's reading. Works in Opera fine! I wouldn't bother with IE ordinarily, but funny thing is a guy I work really loves watching those lines go by and I could get a couple of beers out of it I reckon. Odd, he's almost, I dunno, like he's got log files on the brain or something!
I'm "lucky" in that my commercial site has steady but not overwhelming traffic, such that real time log watching is possible - there is rarely more than one person on the site at a time.
I do a couple of things with cookies and Apache configuration to make this a more manageable process.
Firstly, I have a "secret" page on my site that sets a cookie called "nolog". I then have a bunch of SetEnvIf lines in httpd.conf that decide whether or not to log a request.
They first line is:
SetEnvIfNoCase Request_URI .* normalrequest=true
Which sets an environment variable "normalrequest" to start off with the "log everything" case.
Then...
SetEnvIfNoCase Request_URI \.gif$!normalrequest
SetEnvIfNoCase Cookie .*nolog.*!normalrequest
...which clear "normalrequest" if the request is for a .gif image or from me (because of the nolog cookie). Similar lines kill logging for .css, bots etc.
This is used together with...
CustomLog [existing parameters] env=normalrequest
Probably an easier way to do all that using .htaccess and subdirs. and what not, but it only took a few minutes to setup.
Since developed a impulsive glance towards my logging monitor whenever my peripheral vision detects a shift up the screen!
SetEnvIfNoCase Request_URI "\.(gif¦jpeg¦jpg¦png¦css¦js¦swf¦pdf)$" notapage
SetEnvIfNoCase Remote_Addr "127\.0\.0\.0" notapage With "127.0.0.1" being the IP of my workstation.
(I've realised that this is the wrong way to do it, though - it would be much easier to just set what file types are pages, rather than all those that aren't.)
Then it just pipes the results to a script:
CustomLog ¦/path/to/docroot/write-log.sh watching env=!notapage "write-referer-log.sh" just reads the line in, checks if it matches some stuff I'm not interested in, and writes a line to the log if not. It kind of sucks because the script has to be loaded and executed (which in turn opens the log file, writes a line, and closes it) for every hit. It's not like the server's falling over or anything, but it's sort of offensive to anyone who cares about efficiency.
It would be nice to have another monitor though! I've developed a sort of nervous twitch - if I don't flip to the window with logs open once every couple of minutes it feels like something's not quite right...