Completed
Push — master ( 9d0a53...ecd7bc )
by Maik
01:48
created

ExceptionLoggerTrait::logException()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 16
ccs 0
cts 14
cp 0
rs 9.4285
cc 3
eloc 10
nc 3
nop 1
crap 12
1
<?php
2
3
/**
4
 * This file is part of the PHP Generics package.
5
 *
6
 * @package Generics
7
 */
8
namespace Generics\Logger;
9
10
use Psr\Log\LogLevel;
11
use ErrorException;
12
use Exception;
13
use RuntimeException;
14
15
/**
16
 * Implementation for logging exceptions
17
 *
18
 * @author Maik Greubel <[email protected]>
19
 */
20
trait ExceptionLoggerTrait
21
{
22
23
    abstract protected function logImpl($level, $message, array $context = array());
24
25
    /**
26
     *
27
     * {@inheritdoc}
28
     * @see \Generics\Logger\ExceptionLogger::logException()
29
     */
30
    public function logException(Exception $ex)
31
    {
32
        $level = LogLevel::ALERT;
33
        
34
        if ($ex instanceof ErrorException) {
0 ignored issues
show
Bug introduced by
The class ErrorException does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
35
            $level = LogLevel::ERROR;
36
        } elseif ($ex instanceof RuntimeException) {
37
            $level = LogLevel::EMERGENCY;
38
        }
39
        
40
        $this->logImpl($level, "({code}): {message}\n{stackTrace}", array(
41
            'code' => $ex->getCode(),
42
            'message' => $ex->getMessage(),
43
            'stackTrace' => $ex->getTraceAsString()
44
        ));
45
    }
46
}
47