LogTrait   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 60
rs 10
c 0
b 0
f 0
wmc 11
lcom 1
cbo 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A emergency() 0 4 1
A alert() 0 4 1
A critical() 0 4 1
A error() 0 4 1
A warning() 0 4 1
A notice() 0 4 1
A info() 0 4 1
A debug() 0 4 1
A toLogMessage() 0 8 2
A log() 0 8 1
1
<?php
2
3
namespace Bludata\Lumen\Traits;
4
5
use Psr\Log\LoggerInterface;
6
7
trait LogTrait
8
{
9
    public function emergency($message, array $context = [])
10
    {
11
        $this->log(\Psr\Log\LogLevel::EMERGENCY, $message, $context);
12
    }
13
14
    public function alert($message, array $context = [])
15
    {
16
        $this->log(\Psr\Log\LogLevel::ALERT, $message, $context);
17
    }
18
19
    public function critical($message, array $context = [])
20
    {
21
        $this->log(\Psr\Log\LogLevel::CRITICAL, $message, $context);
22
    }
23
24
    public function error($message, array $context = [])
25
    {
26
        $this->log(\Psr\Log\LogLevel::ERROR, $message, $context);
27
    }
28
29
    public function warning($message, array $context = [])
30
    {
31
        $this->log(\Psr\Log\LogLevel::WARNING, $message, $context);
32
    }
33
34
    public function notice($message, array $context = [])
35
    {
36
        $this->log(\Psr\Log\LogLevel::NOTICE, $message, $context);
37
    }
38
39
    public function info($message, array $context = [])
40
    {
41
        $this->log(\Psr\Log\LogLevel::INFO, $message, $context);
42
    }
43
44
    public function debug($message, array $context = [])
45
    {
46
        $this->log(\Psr\Log\LogLevel::DEBUG, $message, $context);
47
    }
48
49
    public function toLogMessage($value)
50
    {
51
        if (!is_string($value)) {
52
            return print_r($value, true);
53
        }
54
55
        return $value;
56
    }
57
58
    public function log($level, $message, array $context = [])
59
    {
60
        $logger = app(LoggerInterface::class);
61
62
        $log = $this->toLogMessage($message);
63
64
        $logger->log($level, $log, $context);
65
    }
66
}
67