Tuesday, January 15, 2013

Re: custom logger

You got your answer here
http://stackoverflow.com/questions/14331152/custom-log-method

PS: Multiposts should be avoided


Am Dienstag, 15. Januar 2013 04:55:49 UTC+1 schrieb sixthpoint:
Typo, core.php should be bootstrap.php above

On Monday, January 14, 2013 9:54:26 PM UTC-6, sixthpoint wrote:
I am trying to make my own custom logger but the write method gets called twice oddly enough. Here is the code I am using

DatabaseLogger.php in the Lib/Engine/ directory:

App::uses('CakeLogInterface', 'Log');

class DatabaseLogger implements CakeLogInterface {
private $types = array();
    public function __construct($options = array()) {
// Allowed method calls
$this->types = $options['types'];
    }

    public function write($type = NULL, $message = NULL) {

// Only store to cache types that are permitted, other errors from cake are not reported
if(!empty($this->types) && in_array($type, $this->types))
{
    //make database entry here
}
    } 
}

 Here is my core.php setup:


/**
 * Configures default file logging options
 */
App::uses('CakeLog', 'Log');
CakeLog::config('debug', array(
'engine' => 'FileLog',
'types' => array('notice', 'info', 'debug'),
'file' => 'debug',
));
CakeLog::config('error', array(
'engine' => 'FileLog',
'types' => array('warning', 'error', 'critical', 'alert', 'emergency'),
'file' => 'error',
));

// Custom configuration for Couchbase error loggin
CakeLog::config('mytest', array(
    'engine' => 'DatabaseLogger',
'types' => array('mytest'),
'scope' => array(),
'file' => '',
));

To use my log I call the method like so:

CakeLog::write('mytest', 'this message!');


Oddly enough if I put a debug statement in the code for the DatabaseLogger it stop. I have no idea why it does that. Can anyone please help me understand why this is getting called twice?

thanks in advance 
 

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
 
 

No comments: