Logging system
This page describes the logging system for infoarena2. You should use these functions instead of things like print, echo, print_r, assert, etc. If you see these functions used in the code then feel free to change them to the log_* family of functions.
Info-arena logging system is built on top of php's error reporting facilities; It gives E_USER_(NOTICE|WARNING|ERROR) "messages". All of php's errors are considered fatal, except for E_USER_NOTICE and E_USER_WARNING. Because we use php's logging various php.ini settings affect our messages as well.
By default, all debug messages (including the ones from PHP itself) are hidden from the user and instead placed in the server error log (/var/log/apache2/error.log for instance). If you're an unix user you can do something like tail -f /var/log/apache2/error.log in a separate terminal to monitor debug output. For windows, you can search for a tail-like utility, check mtail.
Functions
The logging system is implemented in common/log.php. The functions you should use are:
- log_print(msg, origin=false): for various logging messages. Try not to abuse these messages. Feel free to leave commented log_print calls in the code if you think you might need them later on.
- log_warn(msg, origin=false): warning messages. Use this when something is suspicious.
- log_error(msg, origin=false): Use this for fatal error messages. NOTE: This function will stop the script.
- log_backtrace: This will print a complete backtrace.
- log_assert(cond, msg, origin=true): Use this to check a condition, and die if the condition is not fullfiled. Assert will still be checked in production code, so you can depend on their execution. Don't use this for form validation because the user doesn't get to see your message.
- log_print_r($var): Same as php's print_r except it prints as E_USER_NOTICE.
- log_var_dump($var): Same as php's var_dump except it prints as E_USER_NOTICE.
The optional origin parameter determines if the origin of the message is included (something like "file xxx.php line 123"). This defaults to false because it clutters up the error log, except for assertions.
Usage notes
- Don't leave junk in the log file, comment what you don't need. In www we should only see the server request and security queries.
- the @ operator will supress all error messages, including those given by log_*. This is a good thing.
![[infoarena] development](/chrome/site/logo.png)