1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org) |
4
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) |
5
|
|
|
* |
6
|
|
|
* Licensed under The MIT License |
7
|
|
|
* For full copyright and license information, please see the LICENSE.txt |
8
|
|
|
* Redistributions of files must retain the above copyright notice. |
9
|
|
|
* |
10
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) |
11
|
|
|
* @link https://cakefoundation.org CakePHP(tm) Project |
12
|
|
|
* @since 2.2.0 |
13
|
|
|
* @license https://opensource.org/licenses/mit-license.php MIT License |
14
|
|
|
*/ |
15
|
|
|
namespace Cake\Log\Engine; |
16
|
|
|
|
17
|
|
|
use Cake\Console\ConsoleOutput; |
18
|
|
|
use InvalidArgumentException; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Console logging. Writes logs to console output. |
22
|
|
|
*/ |
23
|
|
|
class ConsoleLog extends BaseLog |
24
|
|
|
{ |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Default config for this class |
28
|
|
|
* |
29
|
|
|
* @var array |
30
|
|
|
*/ |
31
|
|
|
protected $_defaultConfig = [ |
32
|
|
|
'stream' => 'php://stderr', |
33
|
|
|
'levels' => null, |
34
|
|
|
'scopes' => [], |
35
|
|
|
'outputAs' => null, |
36
|
|
|
]; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Output stream |
40
|
|
|
* |
41
|
|
|
* @var \Cake\Console\ConsoleOutput |
42
|
|
|
*/ |
43
|
|
|
protected $_output; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Constructs a new Console Logger. |
47
|
|
|
* |
48
|
|
|
* Config |
49
|
|
|
* |
50
|
|
|
* - `levels` string or array, levels the engine is interested in |
51
|
|
|
* - `scopes` string or array, scopes the engine is interested in |
52
|
|
|
* - `stream` the path to save logs on. |
53
|
|
|
* - `outputAs` integer or ConsoleOutput::[RAW|PLAIN|COLOR] |
54
|
|
|
* |
55
|
|
|
* @param array $config Options for the FileLog, see above. |
56
|
|
|
* @throws \InvalidArgumentException |
57
|
|
|
*/ |
58
|
|
|
public function __construct(array $config = []) |
59
|
|
|
{ |
60
|
|
|
parent::__construct($config); |
61
|
|
|
|
62
|
|
|
$config = $this->_config; |
63
|
|
|
if ($config['stream'] instanceof ConsoleOutput) { |
64
|
|
|
$this->_output = $config['stream']; |
65
|
|
|
} elseif (is_string($config['stream'])) { |
66
|
|
|
$this->_output = new ConsoleOutput($config['stream']); |
67
|
|
|
} else { |
68
|
|
|
throw new InvalidArgumentException('`stream` not a ConsoleOutput nor string'); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
if (isset($config['outputAs'])) { |
72
|
|
|
$this->_output->setOutputAs($config['outputAs']); |
|
|
|
|
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Implements writing to console. |
78
|
|
|
* |
79
|
|
|
* @param string $level The severity level of log you are making. |
80
|
|
|
* @param string $message The message you want to log. |
81
|
|
|
* @param array $context Additional information about the logged message |
82
|
|
|
* @return bool success of write. |
83
|
|
|
*/ |
84
|
|
|
public function log($level, $message, array $context = []) |
85
|
|
|
{ |
86
|
|
|
$message = $this->_format($message, $context); |
87
|
|
|
$output = date('Y-m-d H:i:s') . ' ' . ucfirst($level) . ': ' . $message; |
88
|
|
|
|
89
|
|
|
return (bool)$this->_output->write(sprintf('<%s>%s</%s>', $level, $output, $level)); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: