Web:Extend provides a simple function for logging: weeLog.
weeLog will simply format the message according to WEE_LOG_FORMAT and send it to STDERR.
Most web servers (including Apache or lighttpd) will automatically log everything that is sent to STDERR.
Sending to STDERR ensures that your application will be as performant whether you log or not.
There is no significant performance loss for logging messages using weeLog. You can use it safely in any application.
When using the command line, you can easily manipulate STDERR and redirect it to a file, process it or simply ignore it.
To log a message, simply use:
<?php
weeLog('Sending a message to the log file!');
By default, the log level will be 'notice'.
The message from our above example will look like this:
[Sun Nov 09 18:27:05 2008] [notice] [wee] Sending a message to the log file!
To change the level of the log message, simply add a second parameter. For example you could use the following to log an error:
<?php
weeLog('An error happened!', 'error');
It will results in:
[Sun Nov 09 18:27:05 2008] [error] [wee] An error happened!
By default the error message is formatted using Apache's default log format.
You can of course define your own format.
To do so, simply define WEE_LOG_FORMAT in your boostrap file.
For example you could use:
<?php
define('WEE_LOG_FORMAT', '[%c] [%2$s] [myapp] %1$s');
Where %c is the current time and date,
%1$s is the message and %2$s the message level.
The format string is passed through strftime first so you can define the date format to your liking.