我使用Zend记录器如下: -
$columnMapping = array('message' => 'message', 'created_at' => 'timestamp');
$writer = new Zend_Log_Writer_Db($dbAdapater, 'log', $columnMapping);
$logger = new Zend_Log($writer);
$logger->info('Sample log data');
现在,如果我想绑定更多未定义为默认值的字段(正如我们在 $ columnMapping 数组中看到的那样),例如user_name,user_type等,那我该怎么办?
为了简单起见,我想实现以下目标: -
$columnMapping = array('user_defined_field1' => 'user_defined_val_1');
$writer = new Zend_Log_Writer_Db($dbAdapater, 'log', $columnMapping);
$logger = new Zend_Log($writer);
$logger->info('Sample log data');
请建议。
答案 0 :(得分:1)
记录器定义:
$columnMapping = array(
'message' => 'message',
'user_defined_field1' => 'user_defined_field1');
$writer = new Zend_Log_Writer_Db($dbAdapater, 'log', $columnMapping);
$logger = new Zend_Log($writer);
当'user_defined_val1'数据可用时,调用setEventItem()函数:
$logger->setEventItem('user_defined_field1', 'user_defined_val1');
$logger->info('Sample log data');
更多细节:
http://framework.zend.com/manual/en/zend.log.overview.html - 了解日志事件