for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* This file is part of the PHP Generics package.
*
* @package Generics
*/
namespace Generics\Logger;
use Psr\Log\LogLevel;
use ErrorException;
use Exception;
use RuntimeException;
* Implementation for logging exceptions
* @author Maik Greubel <[email protected]>
trait ExceptionLoggerTrait
{
abstract protected function logImpl($level, $message, array $context = array());
* {@inheritdoc}
* @see \Generics\Logger\ExceptionLogger::logException()
public function logException(Exception $ex)
$level = LogLevel::ALERT;
if ($ex instanceof ErrorException) {
ErrorException
$level = LogLevel::ERROR;
} elseif ($ex instanceof RuntimeException) {
$level = LogLevel::EMERGENCY;
}
$this->logImpl($level, "({code}): {message}\n{stackTrace}", array(
'code' => $ex->getCode(),
'message' => $ex->getMessage(),
'stackTrace' => $ex->getTraceAsString()
));