|
1
|
|
|
<?php namespace Arcanedev\Composer\Utilities; |
|
2
|
|
|
|
|
3
|
|
|
use Composer\IO\IOInterface; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Class Logger |
|
7
|
|
|
* |
|
8
|
|
|
* @package Arcanedev\Composer\Utilities |
|
9
|
|
|
* @author ARCANEDEV <[email protected]> |
|
10
|
|
|
*/ |
|
11
|
|
|
class Logger |
|
12
|
|
|
{ |
|
13
|
|
|
/* ----------------------------------------------------------------- |
|
14
|
|
|
| Properties |
|
15
|
|
|
| ----------------------------------------------------------------- |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* The log name. |
|
20
|
|
|
* |
|
21
|
|
|
* @var string $name |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $name; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* The log IO instance. |
|
27
|
|
|
* |
|
28
|
|
|
* @var \Composer\IO\IOInterface $io |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $io; |
|
31
|
|
|
|
|
32
|
|
|
/* ----------------------------------------------------------------- |
|
33
|
|
|
| Constructor |
|
34
|
|
|
| ----------------------------------------------------------------- |
|
35
|
|
|
*/ |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Make Logger instance. |
|
39
|
|
|
* |
|
40
|
|
|
* @param string $name |
|
41
|
|
|
* @param \Composer\IO\IOInterface $io |
|
42
|
|
|
*/ |
|
43
|
129 |
|
public function __construct($name, IOInterface $io) |
|
44
|
|
|
{ |
|
45
|
129 |
|
$this->name = $name; |
|
46
|
129 |
|
$this->io = $io; |
|
47
|
129 |
|
} |
|
48
|
|
|
|
|
49
|
|
|
/* ----------------------------------------------------------------- |
|
50
|
|
|
| Main Methods |
|
51
|
|
|
| ----------------------------------------------------------------- |
|
52
|
|
|
*/ |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Log an info message. |
|
56
|
|
|
* |
|
57
|
|
|
* Messages will be output at the "verbose" logging level |
|
58
|
|
|
* (eg `-v` needed on the Composer command). |
|
59
|
|
|
* |
|
60
|
|
|
* @param string $message |
|
61
|
|
|
*/ |
|
62
|
105 |
|
public function info($message) |
|
63
|
|
|
{ |
|
64
|
105 |
|
if ($this->io->isVerbose()) { |
|
65
|
3 |
|
$message = " <info>[{$this->name}]</info> {$message}"; |
|
66
|
|
|
|
|
67
|
3 |
|
$this->log($message); |
|
68
|
|
|
} |
|
69
|
105 |
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Log a debug message. |
|
73
|
|
|
* |
|
74
|
|
|
* Messages will be output at the "very verbose" logging level |
|
75
|
|
|
* (eg `-vv` needed on the Composer command). |
|
76
|
|
|
* |
|
77
|
|
|
* @param string $message |
|
78
|
|
|
*/ |
|
79
|
111 |
|
public function debug($message) |
|
80
|
|
|
{ |
|
81
|
111 |
|
if ($this->io->isVeryVerbose()) { |
|
82
|
3 |
|
$message = " <info>[{$this->name}]</info> {$message}"; |
|
83
|
|
|
|
|
84
|
3 |
|
$this->log($message); |
|
85
|
|
|
} |
|
86
|
111 |
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Log a warning message. |
|
90
|
|
|
* |
|
91
|
|
|
* @param string $message |
|
92
|
|
|
*/ |
|
93
|
6 |
|
public function warning($message) |
|
94
|
|
|
{ |
|
95
|
6 |
|
$message = " <error>[{$this->name}]</error> {$message}"; |
|
96
|
|
|
|
|
97
|
6 |
|
$this->log($message); |
|
98
|
6 |
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Write a message. |
|
102
|
|
|
* |
|
103
|
|
|
* @param string $message |
|
104
|
|
|
*/ |
|
105
|
12 |
|
protected function log($message) |
|
106
|
|
|
{ |
|
107
|
12 |
|
if (method_exists($this->io, 'writeError')) { |
|
108
|
12 |
|
$this->io->writeError($message); |
|
109
|
|
|
} |
|
110
|
|
|
else { |
|
111
|
|
|
// @codeCoverageIgnoreStart |
|
112
|
|
|
$this->io->write($message); |
|
113
|
|
|
// @codeCoverageIgnoreEn |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|