|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Seasx\SeasLogger; |
|
5
|
|
|
|
|
6
|
|
|
use Exception; |
|
7
|
|
|
use Seaslog; |
|
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class SeaslogConfig |
|
11
|
|
|
* @package Seasx\SeasLogger |
|
12
|
|
|
*/ |
|
13
|
|
|
class SeaslogConfig extends AbstractConfig |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* SeaslogConfig constructor. |
|
17
|
|
|
* @param array $target |
|
18
|
|
|
* @param array $configs |
|
19
|
|
|
*/ |
|
20
|
|
|
public function __construct(array $target, array $configs = []) |
|
21
|
|
|
{ |
|
22
|
|
|
$this->template = explode($this->split, ini_get('seaslog.default_template')); |
|
23
|
|
|
ini_set('seaslog.recall_depth', (string)$this->recall_depth); |
|
24
|
|
|
parent::__construct($target, $configs); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @return array |
|
29
|
|
|
*/ |
|
30
|
|
|
public function getBuffer(): array |
|
31
|
|
|
{ |
|
32
|
|
|
$buffer = Seaslog::getBuffer(); |
|
33
|
|
|
return $buffer !== false ? $buffer : []; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function getDatetimeFormat(): string |
|
37
|
|
|
{ |
|
38
|
|
|
return SeasLog::getDatetimeFormat(); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function setDatetimeFormat(string $format): bool |
|
42
|
|
|
{ |
|
43
|
|
|
return SeasLog::setDatetimeFormat($format); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @param string $level |
|
49
|
|
|
* @param string $message |
|
50
|
|
|
* @param array $context |
|
51
|
|
|
* @throws Exception |
|
52
|
|
|
*/ |
|
53
|
|
|
public function log(string $level, string $message, array $context = []): void |
|
54
|
|
|
{ |
|
55
|
|
|
$template = $this->getUserTemplate(); |
|
56
|
|
|
$module = ArrayHelper::remove($context, 'module'); |
|
57
|
|
|
if ($module !== null) { |
|
58
|
|
|
Seaslog::setLogger($this->appName . '_' . $module); |
|
59
|
|
|
} |
|
60
|
|
|
isset($template['%Q']) && Seaslog::setRequestID($template['%Q']); |
|
61
|
|
|
foreach (array_filter([ |
|
62
|
|
|
SEASLOG_REQUEST_VARIABLE_DOMAIN_PORT => isset($template['%D']) ? $template['%D'] : null, |
|
|
|
|
|
|
63
|
|
|
SEASLOG_REQUEST_VARIABLE_REQUEST_URI => isset($template['%R']) ? $template['%R'] : null, |
|
|
|
|
|
|
64
|
|
|
SEASLOG_REQUEST_VARIABLE_REQUEST_METHOD => isset($template['%m']) ? $template['%m'] : null, |
|
|
|
|
|
|
65
|
|
|
SEASLOG_REQUEST_VARIABLE_CLIENT_IP => isset($template['%I']) ? $template['%I'] : null |
|
|
|
|
|
|
66
|
|
|
]) as $key => $value) { |
|
67
|
|
|
Seaslog::setRequestVariable($key, $value); |
|
68
|
|
|
} |
|
69
|
|
|
if (!empty($template = ArrayHelper::remove($context, 'template', []) ?? ArrayHelper::remove($template, '%A', |
|
70
|
|
|
[]))) { |
|
71
|
|
|
switch ($this->customerType) { |
|
72
|
|
|
case AbstractConfig::TYPE_JSON: |
|
73
|
|
|
$template = json_encode($template, JSON_UNESCAPED_UNICODE); |
|
74
|
|
|
break; |
|
75
|
|
|
case AbstractConfig::TYPE_FIELD: |
|
76
|
|
|
$template = implode($this->split, $template); |
|
77
|
|
|
} |
|
78
|
|
|
$message = $template . $this->split . $message; |
|
79
|
|
|
} |
|
80
|
|
|
Seaslog::$level($message); |
|
81
|
|
|
$this->flush(); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @param bool $flush |
|
86
|
|
|
* @throws Exception |
|
87
|
|
|
*/ |
|
88
|
|
|
public function flush(bool $flush = false): void |
|
89
|
|
|
{ |
|
90
|
|
|
if (method_exists('Seaslog', 'getBufferCount')) { |
|
91
|
|
|
if (($flush || ($total = Seaslog::getBufferCount()) >= $this->bufferSize) && ($buffer = Seaslog::getBuffer()) !== false) { |
|
|
|
|
|
|
92
|
|
|
Seaslog::flushBuffer(0); |
|
93
|
|
|
foreach ($this->targetList as $index => $target) { |
|
94
|
|
|
rgo(function () use ($target, $buffer, $flush) { |
|
|
|
|
|
|
95
|
|
|
$target->export($buffer); |
|
96
|
|
|
}); |
|
97
|
|
|
} |
|
98
|
|
|
unset($buffer); |
|
99
|
|
|
} |
|
100
|
|
|
} elseif ($flush) { |
|
101
|
|
|
Seaslog::flushBuffer(); |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths