Register the module in bootstrap.php:
Kohana::modules(array(
[...]
'dblog' => MODPATH.'dblog',
));
Create a database table, based on default.sql. Additional fields can be added.
If you want to store all Kohana::$log messages in the database too:
In bootstrap.php
change (or add)
Kohana::$log->attach(new Kohana_Log_File(APPPATH.'logs'));
to
Kohana::$log->attach(new DBlog_Writer());
Make sure this line appears after the call of Kohana::modules().
DBlog::add('NOTICE', 'Log demo title', 'Log demo details: :params', array(':params' => chr(10).print_r($_GET, TRUE)));
DBlog::add('category', 'title', 'details', array(), array(
'client_ip' => getenv('REMOTE_ADDR'),
'url' => getenv('REQUEST_URI'),
));
Log::instance()->add(Log::NOTICE, 'My Logged Message Here');
Module will try to find corresponding message level and save it as type (in the example above, Log::NOTICE
will be translated to 'NOTICE'
).
- Copy
modules/dblog/config/dblog.php
toapplication/config/
- You can change the log table name and pagination settings
The controller should not be accessed directly. You can embed it in your controller with an internal request.
Example with Controller_Demo
:
$this->template->content = Request::factory('dblog/index')->execute();
You can omit log entries of certain types (e.g. in production environments) by setting the static $omit_types
property.
Example in bootstrap.php
:
if (Kohana::$environment === Kohana::PRODUCTION)
{
DBlog::$omit_types = array('NOTICE');
}