コード例 #1
0
ファイル: BaseController.php プロジェクト: a4501150/FDUGroup
 /**
  * 'onFlush' event handling.
  * This method will be called when the 'flush' method of RLog is called
  * like: <pre>Rays::logger()->flush();</pre>
  * @param $event event object
  */
 public function onFlush($event)
 {
     $logs = $event->getParams();
     if (!empty($logs)) {
         foreach ($logs as $log) {
             $sysLog = new SystemLog(array('host' => Rays::app()->request()->getUserHostAddress(), 'path' => Rays::uri(), 'title' => $this->getHeaderTitle(), 'uri' => Rays::referrerUri(), 'timestamp' => date('Y-m-d H:i:s')));
             $sysLog->userId = Rays::isLogin() ? Rays::user()->id : 0;
             $sysLog->message = $log['message'];
             $level = null;
             switch ($log['level']) {
                 case RLog::LEVEL_ERROR:
                     $level = 2;
                     break;
                 case RLog::LEVEL_INFO:
                     $level = 0;
                     break;
                 case RLog::LEVEL_WARNING:
                     $level = 1;
                     break;
             }
             if ($level === null) {
                 continue;
             }
             $sysLog->severity = $level;
             $sysLog->type = $log['type'];
             $sysLog->save();
             unset($sysLog);
         }
     }
 }