1 | <?php |
||
16 | class Logger extends AbstractLogger |
||
17 | { |
||
18 | /** |
||
19 | * @var array $levels Conversion of the level strings to their numeric representations. |
||
20 | */ |
||
21 | private $levels = [ |
||
22 | LogLevel::EMERGENCY => 1, |
||
23 | LogLevel::ALERT => 2, |
||
24 | LogLevel::CRITICAL => 3, |
||
25 | LogLevel::ERROR => 4, |
||
26 | LogLevel::WARNING => 5, |
||
27 | LogLevel::NOTICE => 6, |
||
28 | LogLevel::INFO => 7, |
||
29 | LogLevel::DEBUG => 8, |
||
30 | ]; |
||
31 | |||
32 | /** |
||
33 | * @var int $level Ignore logging attempts at a level less than this. |
||
34 | */ |
||
35 | private $level; |
||
36 | |||
37 | /** |
||
38 | * @var CLImate $climate The underlying climate instance we are using for output. |
||
39 | */ |
||
40 | private $climate; |
||
41 | |||
42 | /** |
||
43 | * Create a new Logger instance. |
||
44 | * |
||
45 | * @param string $level One of the LogLevel constants |
||
46 | * @param CLImate $climate An existing CLImate instance to use for output |
||
47 | */ |
||
48 | public function __construct($level = LogLevel::INFO, CLImate $climate = null) |
||
76 | |||
77 | |||
78 | /** |
||
79 | * Get a numeric log level for the passed parameter. |
||
80 | * |
||
81 | * @param string $level One of the LogLevel constants |
||
82 | * |
||
83 | * @return int |
||
84 | */ |
||
85 | private function convertLevel($level) |
||
94 | |||
95 | |||
96 | /** |
||
97 | * Get a new instance logging at a different level |
||
98 | * |
||
99 | * @param string $level One of the LogLevel constants |
||
100 | * |
||
101 | * @return Logger |
||
102 | */ |
||
103 | public function withLogLevel($level) |
||
109 | |||
110 | |||
111 | /** |
||
112 | * Log messages to a CLImate instance. |
||
113 | * |
||
114 | * @param string $level One of the LogLevel constants |
||
115 | * @param string|object $message If an object is passed it must implement __toString() |
||
116 | * @param array $context Placeholders to be substituted in the message |
||
117 | * |
||
118 | * @return void |
||
119 | */ |
||
120 | public function log($level, $message, array $context = []) |
||
147 | |||
148 | |||
149 | /** |
||
150 | * Handle recursive arrays in the logging context. |
||
151 | * |
||
152 | * @param string $level One of the LogLevel constants |
||
153 | * @param array $context The array of context to output |
||
154 | * @param int $indent The current level of indentation to be used |
||
155 | * |
||
156 | * @return void |
||
157 | */ |
||
158 | private function outputRecursiveContext($level, array $context, $indent) |
||
174 | } |
||
175 |