Skip to content

Commit 6760375

Browse files
committed
Исправление ошибок
- [FIX] Исправлена (https://skripters.biz/forum/threads/dle-api.50709/post-499483)[заявленная ошибка], - [FIX] Исправлена (https://skripters.biz/forum/threads/dle-api.50709/post-499640)[заявленная ошибка]
1 parent f77919d commit 6760375

File tree

14 files changed

+736
-69
lines changed

14 files changed

+736
-69
lines changed

upload/api/composer.lock

Lines changed: 2 additions & 50 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php declare(strict_types=1);
2+
3+
/*
4+
* This file is part of the Monolog package.
5+
*
6+
* (c) Jordi Boggiano <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Monolog\Formatter;
13+
14+
use Monolog\Level;
15+
use Monolog\LogRecord;
16+
17+
/**
18+
* Serializes a log message according to RFC 5424
19+
*
20+
* @author Dalibor Karlović <[email protected]>
21+
* @author Renat Gabdullin <[email protected]>
22+
*/
23+
class SyslogFormatter extends LineFormatter
24+
{
25+
private const SYSLOG_FACILITY_USER = 1;
26+
private const FORMAT = "<%extra.priority%>1 %datetime% %extra.hostname% %extra.app-name% %extra.procid% %channel% %extra.structured-data% %level_name%: %message% %context% %extra%\n";
27+
private const NILVALUE = '-';
28+
29+
private string $hostname;
30+
private int $procid;
31+
32+
public function __construct(private string $applicationName = self::NILVALUE)
33+
{
34+
parent::__construct(self::FORMAT, 'Y-m-d\TH:i:s.uP', true, true);
35+
$this->hostname = (string) gethostname();
36+
$this->procid = (int) getmypid();
37+
}
38+
39+
public function format(LogRecord $record): string
40+
{
41+
$record->extra = $this->formatExtra($record);
42+
43+
return parent::format($record);
44+
}
45+
46+
/**
47+
* @param LogRecord $record
48+
* @return array<string, mixed>
49+
*/
50+
private function formatExtra(LogRecord $record): array
51+
{
52+
$extra = $record->extra;
53+
$extra['app-name'] = $this->applicationName;
54+
$extra['hostname'] = $this->hostname;
55+
$extra['procid'] = $this->procid;
56+
$extra['priority'] = self::calculatePriority($record->level);
57+
$extra['structured-data'] = self::NILVALUE;
58+
59+
return $extra;
60+
}
61+
62+
private static function calculatePriority(Level $level): int
63+
{
64+
return (self::SYSLOG_FACILITY_USER * 8) + $level->toRFC5424Level();
65+
}
66+
}
Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
<?php declare(strict_types=1);
2+
3+
/*
4+
* This file is part of the Monolog package.
5+
*
6+
* (c) Jordi Boggiano <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Monolog;
13+
14+
use Psr\Log\LogLevel;
15+
16+
/**
17+
* Represents the log levels
18+
*
19+
* Monolog supports the logging levels described by RFC 5424 {@see https://datatracker.ietf.org/doc/html/rfc5424}
20+
* but due to BC the severity values used internally are not 0-7.
21+
*
22+
* To get the level name/value out of a Level there are several options:
23+
*
24+
* - Use ->getName() to get the standard Monolog name which is full uppercased (e.g. "DEBUG")
25+
* - Use ->toPsrLogLevel() to get the standard PSR-3 name which is full lowercased (e.g. "debug")
26+
* - Use ->toRFC5424Level() to get the standard RFC 5424 value (e.g. 7 for debug, 0 for emergency)
27+
* - Use ->name to get the enum case's name which is capitalized (e.g. "Debug")
28+
*
29+
* To get the internal value for filtering, if the includes/isLowerThan/isHigherThan methods are
30+
* not enough, you can use ->value to get the enum case's integer value.
31+
*/
32+
enum Level: int
33+
{
34+
/**
35+
* Detailed debug information
36+
*/
37+
case Debug = 100;
38+
39+
/**
40+
* Interesting events
41+
*
42+
* Examples: User logs in, SQL logs.
43+
*/
44+
case Info = 200;
45+
46+
/**
47+
* Uncommon events
48+
*/
49+
case Notice = 250;
50+
51+
/**
52+
* Exceptional occurrences that are not errors
53+
*
54+
* Examples: Use of deprecated APIs, poor use of an API,
55+
* undesirable things that are not necessarily wrong.
56+
*/
57+
case Warning = 300;
58+
59+
/**
60+
* Runtime errors
61+
*/
62+
case Error = 400;
63+
64+
/**
65+
* Critical conditions
66+
*
67+
* Example: Application component unavailable, unexpected exception.
68+
*/
69+
case Critical = 500;
70+
71+
/**
72+
* Action must be taken immediately
73+
*
74+
* Example: Entire website down, database unavailable, etc.
75+
* This should trigger the SMS alerts and wake you up.
76+
*/
77+
case Alert = 550;
78+
79+
/**
80+
* Urgent alert.
81+
*/
82+
case Emergency = 600;
83+
84+
/**
85+
* @param value-of<self::NAMES>|LogLevel::*|'Debug'|'Info'|'Notice'|'Warning'|'Error'|'Critical'|'Alert'|'Emergency' $name
86+
* @return static
87+
*/
88+
public static function fromName(string $name): self
89+
{
90+
return match ($name) {
91+
'debug', 'Debug', 'DEBUG' => self::Debug,
92+
'info', 'Info', 'INFO' => self::Info,
93+
'notice', 'Notice', 'NOTICE' => self::Notice,
94+
'warning', 'Warning', 'WARNING' => self::Warning,
95+
'error', 'Error', 'ERROR' => self::Error,
96+
'critical', 'Critical', 'CRITICAL' => self::Critical,
97+
'alert', 'Alert', 'ALERT' => self::Alert,
98+
'emergency', 'Emergency', 'EMERGENCY' => self::Emergency,
99+
};
100+
}
101+
102+
/**
103+
* @param value-of<self::VALUES> $value
104+
* @return static
105+
*/
106+
public static function fromValue(int $value): self
107+
{
108+
return self::from($value);
109+
}
110+
111+
/**
112+
* Returns true if the passed $level is higher or equal to $this
113+
*/
114+
public function includes(Level $level): bool
115+
{
116+
return $this->value <= $level->value;
117+
}
118+
119+
public function isHigherThan(Level $level): bool
120+
{
121+
return $this->value > $level->value;
122+
}
123+
124+
public function isLowerThan(Level $level): bool
125+
{
126+
return $this->value < $level->value;
127+
}
128+
129+
/**
130+
* Returns the monolog standardized all-capitals name of the level
131+
*
132+
* Use this instead of $level->name which returns the enum case name (e.g. Debug vs DEBUG if you use getName())
133+
*
134+
* @return value-of<self::NAMES>
135+
*/
136+
public function getName(): string
137+
{
138+
return match ($this) {
139+
self::Debug => 'DEBUG',
140+
self::Info => 'INFO',
141+
self::Notice => 'NOTICE',
142+
self::Warning => 'WARNING',
143+
self::Error => 'ERROR',
144+
self::Critical => 'CRITICAL',
145+
self::Alert => 'ALERT',
146+
self::Emergency => 'EMERGENCY',
147+
};
148+
}
149+
150+
/**
151+
* Returns the PSR-3 level matching this instance
152+
*
153+
* @phpstan-return \Psr\Log\LogLevel::*
154+
*/
155+
public function toPsrLogLevel(): string
156+
{
157+
return match ($this) {
158+
self::Debug => LogLevel::DEBUG,
159+
self::Info => LogLevel::INFO,
160+
self::Notice => LogLevel::NOTICE,
161+
self::Warning => LogLevel::WARNING,
162+
self::Error => LogLevel::ERROR,
163+
self::Critical => LogLevel::CRITICAL,
164+
self::Alert => LogLevel::ALERT,
165+
self::Emergency => LogLevel::EMERGENCY,
166+
};
167+
}
168+
169+
/**
170+
* Returns the RFC 5424 level matching this instance
171+
*
172+
* @phpstan-return int<0, 7>
173+
*/
174+
public function toRFC5424Level(): int
175+
{
176+
return match ($this) {
177+
self::Debug => 7,
178+
self::Info => 6,
179+
self::Notice => 5,
180+
self::Warning => 4,
181+
self::Error => 3,
182+
self::Critical => 2,
183+
self::Alert => 1,
184+
self::Emergency => 0,
185+
};
186+
}
187+
188+
public const VALUES = [
189+
100,
190+
200,
191+
250,
192+
300,
193+
400,
194+
500,
195+
550,
196+
600,
197+
];
198+
199+
public const NAMES = [
200+
'DEBUG',
201+
'INFO',
202+
'NOTICE',
203+
'WARNING',
204+
'ERROR',
205+
'CRITICAL',
206+
'ALERT',
207+
'EMERGENCY',
208+
];
209+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php declare(strict_types=1);
2+
3+
/*
4+
* This file is part of the Monolog package.
5+
*
6+
* (c) Jordi Boggiano <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Monolog\Processor;
13+
14+
use Monolog\LogRecord;
15+
16+
/**
17+
* Generates a context from a Closure if the Closure is the only value
18+
* in the context
19+
*
20+
* It helps reduce the performance impact of debug logs if they do
21+
* need to create lots of context information. If this processor is added
22+
* on the correct handler the context data will only be generated
23+
* when the logs are actually logged to that handler, which is useful when
24+
* using FingersCrossedHandler or other filtering handlers to conditionally
25+
* log records.
26+
*/
27+
class ClosureContextProcessor implements ProcessorInterface
28+
{
29+
public function __invoke(LogRecord $record): LogRecord
30+
{
31+
$context = $record->context;
32+
if (isset($context[0]) && 1 === \count($context) && $context[0] instanceof \Closure) {
33+
try {
34+
$context = $context[0]();
35+
} catch (\Throwable $e) {
36+
$context = [
37+
'error_on_context_generation' => $e->getMessage(),
38+
'exception' => $e,
39+
];
40+
}
41+
42+
if (!\is_array($context)) {
43+
$context = [$context];
44+
}
45+
46+
$record = $record->with(context: $context);
47+
}
48+
49+
return $record;
50+
}
51+
}

0 commit comments

Comments
 (0)