How to override CakePHP Log() function -
i need override default cakephp log() function writes database instead of file. don't care whether or not idea, want know how go firstly overriding happens when go $this->log("blah") , secondly how reference log table element form within app_controller or other class performing override in.
first, create table in database store logs:
create table if not exists `logs` ( `id` int(11) not null auto_increment, `type` varchar(50) collate utf8_unicode_ci not null, `message` varchar(255) collate utf8_unicode_ci not null, primary key (`id`) ) engine=innodb default charset=utf8 collate=utf8_unicode_ci auto_increment=1 ; in app/model directory create file called log.php , put code in it:
<?php class log extends appmodel { var $name = 'log'; function write($type, $message) { $this->save(array( 'log' => array( 'type' => $type, 'message' => $message ) )); } } that's logging engine it's model can customise use different datasource or table. requirement write function accepts parameters.
edit app/config/bootstrap.php , add code @ end of file:
app::import('model','log'); cakelog::config('otherfile', array( 'engine' => 'log', 'model' => 'log', )); you can use log $this->log($type, $message); or $this->log($message); defaults error type.
there info creating custom logging engines in cakephp manual.
Comments
Post a Comment