<p>This example shows how to set up a logging feature in your application. You are able to control the level of logging.</p>
<h3>Database initialisation</h3>
<ac:macro ac:name="code"><ac:default-parameter>php</ac:default-parameter><ac:plain-text-body><![CDATA[
$db->query('CREATE TABLE `log` (
`uid` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
`timestamp` VARCHAR(64),
`lvl` VARCHAR(6),
`msg` VARCHAR(256));
');
]]></ac:plain-text-body></ac:macro>
<h3>config.ini</h3>
<ac:macro ac:name="code"><ac:plain-text-body><![CDATA[
[general]
; Debugging Log level 0 - 7
logLevel = 7
]]></ac:plain-text-body></ac:macro>
<h3>MyPlugin_Logger class</h3>
<ac:macro ac:name="code"><ac:default-parameter>php</ac:default-parameter><ac:plain-text-body><![CDATA[
class MyPlugin_Logger extends Zend_Controller_Plugin_Abstract
{
/**
- Set up logging
*/
public function preDispatch(Zend_Controller_Request_Abstract $request)Unknown macro: { $logLevel = intval(Zend_Registry}}
]]></ac:plain-text-body></ac:macro>
<h3>Example usage</h3>
<ac:macro ac:name="code"><ac:default-parameter>php</ac:default-parameter><ac:plain-text-body><![CDATA[
Zend_Registry::get('logger')->debug('Some Debug Trace!');
Zend_Registry::get('logger')->info('Informational message!');
...
]]></ac:plain-text-body></ac:macro>
1 Comment
comments.show.hideFeb 22, 2011
Aaron S. Hawley
<p>If a value to insert to the table is too large for a column, the wrong type or some other issue, then the log will fail to insert. There needs to be some way to add a Zend_Filter to a Zend_Log_Writer_Db to truncate or smash the data so it still succeeds.</p>