BasicLogging::setLog()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php namespace DiegoCaprioli\Larachimp\Traits;
2
3
use Illuminate\Contracts\Logging\Log;
4
5
/**
6
 * Provides quick and convinient log methods based that used the class 
7
 * configured Log service and based in the package log_level configuration
8
 */
9
trait BasicLogging {
10
11
	/**
12
     * The logger to user
13
     * @var \Illuminate\Contracts\Logging\Log
14
     */
15
    protected $log;
16
17
18
    /**
19
     * Sets the log attribute
20
     * 
21
     * @param Log $log
22
     */
23 5
    public function setLog(Log $log = null)
24
    {
25 5
        $this->log = $log;
26 5
    }
27
28
    /**
29
     * If there's a logger defined, it logs the string
30
     * 
31
     * @param string $string The string to log     
32
     */
33 6
    protected function logInfo($string)
34
    {
35
        if (
36 6
            !empty($this->log) &&
37 6
            config('diegocaprioli.larachimp.larachimp.log_level', 'error') == 'info'
38 6
        ) {
39
            $this->log->info($string);
40
        }
41 6
    }
42
43
    /**
44
     * If there's a logger defined, it logs the string
45
     * 
46
     * @param string $string The string to log     
47
     */
48
    protected function logError($string)
49
    {
50
        if (!empty($this->log)) {
51
            $this->log->error($string);
52
        }
53
    }
54
55
}