Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
7 / 7 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
LoggerTrait | |
100.00% |
7 / 7 |
|
100.00% |
4 / 4 |
7 | |
100.00% |
1 / 1 |
setLogger | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
logLn | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
ln | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
log | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace WebPConvert\Convert\Converters\BaseTraits; |
4 | |
5 | /** |
6 | * Trait for providing logging capabilities. |
7 | * |
8 | * This trait is currently only used in the AbstractConverter class. It has been extracted into a |
9 | * trait in order to bundle the methods concerning logging. |
10 | * |
11 | * @package WebPConvert |
12 | * @author Bjørn Rosell <it@rosell.dk> |
13 | * @since Class available since Release 2.0.0 |
14 | */ |
15 | trait LoggerTrait |
16 | { |
17 | |
18 | /** @var \WebPConvert\Loggers\BaseLogger|null The logger (or null if not set) */ |
19 | protected $logger; |
20 | |
21 | /** |
22 | * Set logger |
23 | * |
24 | * @param \WebPConvert\Loggers\BaseLogger $logger (optional) $logger |
25 | * @return void |
26 | */ |
27 | public function setLogger($logger = null) |
28 | { |
29 | $this->logger = $logger; |
30 | } |
31 | |
32 | /** |
33 | * Write a line to the logger. |
34 | * |
35 | * @param string $msg The line to write. |
36 | * @param string $style (optional) Ie "italic" or "bold" |
37 | * @return void |
38 | */ |
39 | public function logLn($msg, $style = '') |
40 | { |
41 | if (isset($this->logger)) { |
42 | $this->logger->logLn($msg, $style); |
43 | } |
44 | } |
45 | |
46 | /** |
47 | * New line |
48 | * |
49 | * @return void |
50 | */ |
51 | protected function ln() |
52 | { |
53 | if (isset($this->logger)) { |
54 | $this->logger->ln(); |
55 | } |
56 | } |
57 | |
58 | /** |
59 | * Write to the logger, without newline |
60 | * |
61 | * @param string $msg What to write. |
62 | * @param string $style (optional) Ie "italic" or "bold" |
63 | * @return void |
64 | */ |
65 | public function log($msg, $style = '') |
66 | { |
67 | if (isset($this->logger)) { |
68 | $this->logger->log($msg, $style); |
69 | } |
70 | } |
71 | } |