示例#1
0
 /**
  * Create a new log event (Saves a line or two)
  * @param int $level
  * @param string|\Exception $msg
  * @param array $context
  * @param string $appName
  * @param mixed $exceptionToArrayHandler
  * @return LogEvent
  */
 public static function create($level, $msg, array $context, $appName, $exceptionToArrayHandler = null)
 {
     $logEvent = new LogEvent($context);
     $logEvent->setLevel($level);
     if ($msg instanceof \Exception) {
         $exceptionHandler = $exceptionToArrayHandler;
         if (empty($exceptionHandler) || !is_callable($exceptionHandler)) {
             $exceptionHandler = static::DEFAULT_EXCEPTION_HANDLER;
         }
         $logEvent->setException(call_user_func($exceptionHandler, $msg));
         $msg = $msg->getMessage();
     }
     $logEvent->setMsg($msg);
     $logEvent->setName($appName);
     $logEvent->setTime(static::getTimestamp($context));
     return $logEvent;
 }