- //initiate the logger - Log to a file
- $writer = new Zend_Log_Writer_Stream($root.'\log\test.txt');
- $logger = new Zend_Log($writer);
- //Log to Database.
- $columnMap = array('lvl' => 'priority', 'msg' => 'message', 'timestamp' => 'timestamp', 'lvlName' => 'priorityName');
- $dbwriter = new Zend_Log_Writer_Db($db, 'log_table_name', $columnMap);
- $logger->addWriter($dbwriter);
- //Log to firebug
- $writerFirebug = new Zend_Log_Writer_Firebug();
- $writerFirebug->setPriorityStyle(6, 'TRACE');
- $logger->addWriter($writerFirebug);
- $registry->logger = $logger;
Using the logger:
- $logger = Zend_Registry::get('logger');
Log an exception:
- $exception = new Zend_Exception('Test exception');
- $logger->err($exception);
Log a message:
- $logger->info('Show Information about something');
1 comment:
For filtering add following to the bootstrap file:
$filter = new Zend_Log_Filter_Priority(Zend_Log::INFO);
$logger->addFilter($filter);
This will make sure no debug messages are logged.
Post a Comment