By default, the Kohana PHP Framework logs errors to files in the application/logs directory, separated into directories and files for each year, month and day (eg: application/logs/2011/03/16.php).
To change this behaviour to use the system log daemon, you change the following line in bootstrap.php:
Kohana::$log->attach(new Kohana_Log_Syslog('site_identifier', LOG_LOCAL1));
By default, these will probably appear in your /var/log/syslog file (on Debian/Ubuntu anyway – some other distributions use /var/log/messages).
You can configure syslog to put these in their own file by adding this to your syslog configuration file (on Debian/Ubuntu it’s done by adding a file into /etc/rsyslog.d):
If something else is already logging to local1, you can change that and LOG_LOCAL1 above to local2 and LOG_LOCAL2.
If you would like to write your own messages to the log, you can do so with:
Kohana::$log->add(Log::ERROR, 'error text');
Instead of ERROR, you can also use EMERG, ALERT, CRITICAL, WARNING, NOTICE, INFO or DEBUG.
If you would like to pull out different types of errors into different files, you can use this in your syslog configuration:
Note that the errors are not actually written until the request has completed. You can force them to be written with the following:
You can also force this behaviour by setting
Log::$write_on_add = TRUE; in bootstrap.php, but be aware there is an overhead to doing that.
If you would like to ensure that logging is setup before writing to the log, you can do the following:
// Add this exception to the log:
// Make sure the logs are written: