In my bootstrap file I initiate the logger and every thing works fine. What I need now is that the logger also logs the user_id given from the zend_auth instance. Here the logger I initiate:
public function _initLogger(){
$resource = $this->getPluginResource('db');
$dbAdapter = $resource->getDbAdapter();
$columnMapping = array(
'level' => 'priorityName',
'priority' => 'priority',
'message' => 'message',
'created' => 'timestamp',
'user_agent'=> 'user_agent',
'get_vars' => 'get_vars',
'post_vars' => 'post_vars',
'ip' => 'ip',
'id_user' => 'id_user',
);
$auth = Zend_Auth::getInstance();
$writerDb = new Zend_Log_Writer_Db($dbAdapter, 'tbl_log', $columnMapping);
$logger = new Zend_Log($writerDb);
$logger->setEventItem('datetime',date('Y-m-d H:i:s'));
$logger->setEventItem('user_agent',$_SERVER['HTTP_USER开发者_JAVA技巧_AGENT']);
$logger->setEventItem('get_vars',print_r($_GET,true));
$logger->setEventItem('post_vars',print_r($_POST,true));
$logger->setEventItem('ip',$_SERVER['REMOTE_ADDR']);
$logger->setEventItem('id_user',$auth->getIdentity()->id);
$logger->addPriority('login', 10);
$logger->addPriority('logout', 11);
$logger->addPriority('trans', 12);
$logger->addPriority('transfailed', 13);
Zend_Registry::set('logger', $logger);
}
I get no error, but the user id is not stored or retrieved...
During bootstrap, auth information is not available. You need to add the lines:
$logger = Zend_Registry::get('logger');
$logger->setEventItem('id_user',$auth->getIdentity()->id);
After you get identity info from the user (in your login controller).
精彩评论