本文整理匯總了PHP中Psr\Log\LoggerInterface::err方法的典型用法代碼示例。如果您正苦於以下問題:PHP LoggerInterface::err方法的具體用法?PHP LoggerInterface::err怎麽用?PHP LoggerInterface::err使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Psr\Log\LoggerInterface
的用法示例。
在下文中一共展示了LoggerInterface::err方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: onKernelException
/**
* @param GetResponseForExceptionEvent $event
*/
public function onKernelException(GetResponseForExceptionEvent $event)
{
$exception = $event->getException();
$code = $exception->getCode();
$debug = array('class' => get_class($exception), 'code' => $code, 'message' => $exception->getMessage());
$this->logger->err(print_r($debug, TRUE));
// HttpExceptionInterface est un type d'exception spécial qui
// contient le code statut et les détails de l'entête
if ($exception instanceof NotFoundHttpException) {
$data = array('error' => array('code' => $code ? $code : -3, 'message' => $exception->getMessage()));
$response = new JsonResponse($data);
$response->setStatusCode($exception->getStatusCode());
$response->headers->replace($exception->getHeaders());
$response->headers->set('Content-Type', 'application/json');
} elseif ($exception instanceof HttpExceptionInterface) {
$data = array('error' => array('code' => $code ? $code : -2, 'message' => $exception->getMessage()));
$response = new JsonResponse($data);
$response->setStatusCode($exception->getStatusCode());
$response->headers->replace($exception->getHeaders());
$response->headers->set('Content-Type', 'application/json');
} else {
$data = array('error' => array('code' => $code ? $code : -1, 'message' => 'Internal Server Error / ' . $exception->getMessage()));
$response = new JsonResponse($data);
$response->setStatusCode(Response::HTTP_INTERNAL_SERVER_ERROR);
}
// envoie notre objet réponse modifié à l'évènement
$event->setResponse($response);
}
示例2: zendExceptionHandler
/**
* Treat a Zend Ldap Exception.
*
* @param ZendLdapException $exception
*/
protected function zendExceptionHandler(ZendLdapException $exception)
{
switch ($exception->getCode()) {
// Error level codes
case ZendLdapException::LDAP_SERVER_DOWN:
if ($this->logger) {
$this->logger->err($exception->getMessage());
}
break;
// Other level codes
// Other level codes
default:
$this->logDebug($exception->getMessage());
break;
}
}
示例3: handle
public function handle(GetResponseEvent $event)
{
$request = $event->getRequest();
$wsseRegex = '/UsernameToken Username="([^"]+)", PasswordDigest="([^"]+)", Nonce="([^"]+)", Created="([^"]+)"/';
if (!$request->headers->has('x-wsse') || 1 !== preg_match($wsseRegex, $request->headers->get('x-wsse'), $matches)) {
throw new AccessDeniedHttpException('Missing WSSE headers.');
$response = new Response();
$response->setStatusCode(Response::HTTP_FORBIDDEN);
$response->setContent('Missing WSSE headers.');
$event->setResponse($response);
return;
}
$token = new WsseUserToken();
$token->setUser($matches[1]);
$token->digest = $matches[2];
$token->nonce = $matches[3];
$token->created = $matches[4];
try {
$authToken = $this->authenticationManager->authenticate($token);
$this->tokenStorage->setToken($authToken);
return;
} catch (AuthenticationException $failed) {
throw new AccessDeniedHttpException('WSSE Login failed.');
// ... you might log something here
$failedMessage = 'WSSE Login failed for ' . $token->getUsername() . '. Why ? ' . $failed->getMessage();
$this->logger->err($failedMessage);
// To deny the authentication clear the token. This will redirect to the login page.
// Make sure to only clear your token, not those of other authentication listeners.
// $token = $this->tokenStorage->getToken();
// if ($token instanceof WsseUserToken && $this->providerKey === $token->getProviderKey()) {
// $this->tokenStorage->setToken(null);
// }
// return;
// Deny authentication with a '403 Forbidden' HTTP response
$response = new Response();
$response->setStatusCode(Response::HTTP_FORBIDDEN);
$response->setContent($failedMessage);
$event->setResponse($response);
return;
}
// By default deny authorization
$response = new Response();
$response->setStatusCode(Response::HTTP_FORBIDDEN);
$event->setResponse($response);
}
示例4: logException
/**
* Logs exceptions.
*
* @param \Exception $originalException Original exception that called the listener
* @param \Exception $generatedException Generated exception
* @param string|null $message Message to log
*/
private function logException(\Exception $originalException, \Exception $generatedException, $message = null)
{
if (!$message) {
$message = sprintf('Exception thrown when handling an exception (%s: %s)', get_class($generatedException), $generatedException->getMessage());
}
if (null !== $this->logger) {
if (!$originalException instanceof HttpExceptionInterface || $originalException->getStatusCode() >= 500) {
$this->logger->crit($message, array('exception' => $originalException));
} else {
$this->logger->err($message, array('exception' => $originalException));
}
} else {
error_log($message);
}
}
示例5: errInternal
/**
* Adds a log record at the `ERROR` level.
*
* This method allows for compatibility with common interfaces.
*
* @param string $message log message
* @param array $placeholders placeholders for replacement
* @return bool Whether the record has been processed
*/
protected function errInternal($message, array $placeholders = [])
{
return $this->logger->err(StringHelper::replace($message, $placeholders, false), $placeholders);
}