1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* \AppserverIo\WebServer\Loggers\ErrorLogLogger |
5
|
|
|
* |
6
|
|
|
* NOTICE OF LICENSE |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
9
|
|
|
* that is available through the world-wide-web at this URL: |
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
11
|
|
|
* |
12
|
|
|
* PHP version 5 |
13
|
|
|
* |
14
|
|
|
* @author Johann Zelger <[email protected]> |
15
|
|
|
* @copyright 2015 TechDivision GmbH <[email protected]> |
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
17
|
|
|
* @link https://github.com/appserver-io/server |
18
|
|
|
* @link http://www.appserver.io |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace AppserverIo\Server\Loggers; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Logger implementation that uses the PHP 'error_log' function. |
25
|
|
|
* |
26
|
|
|
* @author Johann Zelger <[email protected]> |
27
|
|
|
* @copyright 2015 TechDivision GmbH <[email protected]> |
28
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
29
|
|
|
* @link https://github.com/appserver-io/server |
30
|
|
|
* @link http://www.appserver.io |
31
|
|
|
*/ |
32
|
|
|
class ErrorLogLogger extends DummyLogger |
33
|
|
|
{ |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Logs with an arbitrary level. |
37
|
|
|
* |
38
|
|
|
* @param mixed $level The log level |
39
|
|
|
* @param string $message The message to log |
40
|
|
|
* @param array $context The context for log |
41
|
|
|
* |
42
|
|
|
* @return null |
43
|
|
|
*/ |
44
|
|
|
public function log($level, $message, array $context = array()) |
45
|
|
|
{ |
46
|
|
|
|
47
|
|
|
// check the log level |
48
|
|
|
if ($this->shouldLog($level)) { |
49
|
|
|
// prepare the log message |
50
|
|
|
$logMessage = sprintf('[%s] - %s (%s): %s %s', date('Y-m-d H:i:s'), gethostname(), $level, $message, json_encode($context)); |
51
|
|
|
|
52
|
|
|
// write the log message |
53
|
|
|
error_log($logMessage); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|