1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleLog; |
6
|
|
|
|
7
|
|
|
class LogStatic |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* @var Log |
11
|
|
|
*/ |
12
|
|
|
protected static $instance; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* log event information into file |
16
|
|
|
* |
17
|
|
|
* @param string $level |
18
|
|
|
* @param array|string $message |
19
|
|
|
* @param array $context |
20
|
|
|
* @param array $params |
21
|
|
|
* @throws \ReflectionException |
22
|
|
|
*/ |
23
|
1 |
|
public static function log(string $level, $message, array $context = [], array $params = []): void |
24
|
|
|
{ |
25
|
1 |
|
self::init($params); |
26
|
1 |
|
self::$instance->log($level, $message, $context); |
27
|
1 |
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* log event information into file |
31
|
|
|
* |
32
|
|
|
* @param array|string $message |
33
|
|
|
* @param array $context |
34
|
|
|
* @param array $params |
35
|
|
|
* @throws \ReflectionException |
36
|
|
|
*/ |
37
|
1 |
|
public static function makeLog($message, array $context = [], array $params = []): void |
38
|
|
|
{ |
39
|
1 |
|
self::init($params); |
40
|
1 |
|
self::$instance->makeLog($message, $context); |
41
|
1 |
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* set log option for all future executions of makeLog |
45
|
|
|
* |
46
|
|
|
* @param string $key |
47
|
|
|
* @param mixed $val |
48
|
|
|
* @return Log |
49
|
|
|
* @throws \ReflectionException |
50
|
|
|
*/ |
51
|
2 |
|
public static function setOption(string $key, $val): Log |
52
|
|
|
{ |
53
|
2 |
|
self::init(); |
54
|
2 |
|
return self::$instance->setOption($key, $val); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* return all configuration or only given key value |
59
|
|
|
* |
60
|
|
|
* @param null|string $key |
61
|
|
|
* @return array|mixed |
62
|
|
|
* @throws \ReflectionException |
63
|
|
|
*/ |
64
|
2 |
|
public static function getOption(?string $key = null) |
65
|
|
|
{ |
66
|
2 |
|
self::init(); |
67
|
2 |
|
return self::$instance->getOption($key); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* create Log object if not exists |
72
|
|
|
* |
73
|
|
|
* @param array $params |
74
|
|
|
* @throws \ReflectionException |
75
|
|
|
*/ |
76
|
2 |
|
protected static function init(array $params = []): void |
77
|
|
|
{ |
78
|
2 |
|
if (is_null(self::$instance)) { |
79
|
1 |
|
self::$instance = new Log($params); |
80
|
|
|
} |
81
|
2 |
|
} |
82
|
|
|
} |
83
|
|
|
|