PHP Error Aid
What is it?
PEA is a small
PHP library
to help logging errors. It logs both native PHP errors and PEAR errors, but it
does not require PEAR itself (in which case only PHP errors are logged). It
only logs to files, but it is effortless to convert it to send logs by mail or
the system logger. See
error_log.
Features
Since it is a small library, it has not many features, just what is strictly
needed. Here are the main features:
- Logging of variable informations according to debug levels.
- Transparent support of PEAR errors.
- Log files are friendly to vim by adding
fold markers, for a better log analysis.
This library is mostly useful during website development, where details about
the errors are very useful. It can also be helpful in a production environment
to monitor the correct behaviour of the application, but only for smaller
websites. Bigger projects should implement a smarter logging facility.
Installation instructions
Installation is very simple: copy the errors.php file somewhere in your
project, open it for editing and set the correct path to your log file. Please
make sure that the destination folder exists, that the logfile itself exists
and that the correct permissions are set for writing to the file.
Now you simply have to include this file in every script in your project and
all the errors will be appended to the specified file.
Warning
You should not put the log file in a folder accessible from the web. Put it in
a private area only accessible through ftp (or other authenticated access
mechanism). Important details will be written to this file such as passwords
and query string, so make sure to keep the logs away from unauthorized people.
Tricks and Tips
To analyze your log files you should be using the
VIM editor. Once you have opened the file,
go to command mode (ESC) and just type this:
:set fdm=marker
After you press return, the file should close all the folds in it and give you
an overview of what happened. To open a fold to have details, you should move
over the fold and (in control mode) press
zo To close the fold:
zc
Debugging levels
The errors file defines a DEBUG constant, which is a numeric constant. 0 means
no debugging, so only true errors will be logged with minimal information. 1 is
the basic debug level, it enables some more messages whenever an error is
triggered. Debug levels 2, 3 and 4 are not used right now, but they are
reserved for future uses. Debug level 5 is the top debug level and it also
logs errors that should be ignored (so even errors happening on lines with an @
prepended or masked by the error_reporting value).
License
This library is licenced under the terms of the
modified BSD.
Download
Bugs
If you find a bug you can write me at
webmaster@sbisinger.net.
This package has been written by Stéphane Bisinger.
TODO
There are many many things that could be done to improve this library, but
right now this list stays empty. If you have any suggestions, please e-mail me.