-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathDefaultLogger.php
More file actions
54 lines (49 loc) · 1.32 KB
/
DefaultLogger.php
File metadata and controls
54 lines (49 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
/**
* This file is part of the PageCache package.
*
* @author Denis Terekhov <i.am@spotman.ru>
* @package PageCache
* @copyright 2017
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PageCache;
use Psr\Log\AbstractLogger;
class DefaultLogger extends AbstractLogger
{
private $file;
/**
* DefaultLogger constructor.
*
* @param $file
*/
public function __construct($file)
{
$this->file = $file;
}
/**
* Logs with an arbitrary level.
*
* @param mixed $level
* @param string $message
* @param array $context
*
* @return void
*/
public function log($level, string|\Stringable $message, array $context = []): void
{
$exception = isset($context['exception']) ? $context['exception'] : null;
$microTime = microtime(true);
$micro = sprintf("%06d", ($microTime - floor($microTime)) * 1000000);
$logTime = (new \DateTime(date('Y-m-d H:i:s.' . $micro, (int)$microTime)))->format('Y-m-d H:i:s.u');
error_log(
'[' . $logTime . '] '
.$message.($exception ? ' {Exception: '.$exception->getMessage().'}' : '')."\n",
3,
$this->file,
null
);
}
}