I want to create a script that parses or makes sense of apache's error log to see what the most recent error was. I was wondering if anyone out there has something that does this or has any ideas where to start?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
for anyone else looking for a sample script, i threw something together, it's got the basics:
Here's a small-ish class that makes it easy to read a number of characters from the back of a large file w/o overloading memory. The test setting lets you see it in action cannibalizing itself.
There are a few things to consider first:
However, if none of these apply, you can use the normal file reading commands to do it. The easiest way to get the last error is
There's probably a better way of doing this that doesn't oink up memory, but I'll leave that as an exercise for the reader.
One last comment: PHP also has an ini setting to redirect PHP errors to a log file:
error_log = /path/to/error.log
You can set this in httpd.conf or in an .htaccess file (if you have access to one) using the php_flag notation:
Have you tried biterScripting ? I am a system admin and I have been using to parse logs. It is univx style scripting. biterScripting.com -> Free download.
there are piles of php scripts that do this, just do a google search for examples. if you want to roll your own, it's nothing more complex than reading any other file. just make sure you know the location of your logfiles (defined in the httpd.conf file) and the format your log files are in. the format is also defined in httpd.conf