Completed
Push — master ( 2f8d3d...2248bd )
by Jonathan André
02:54
created

LogTrait::log()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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