golden hour
/home/doctorbruno/.trash/google-site-kit.1/third-party/monolog/monolog/src/Monolog/Handler
⬆️ Go Up
Upload
File/Folder
Size
Actions
AbstractHandler.php
2.69 KB
Del
OK
AbstractProcessingHandler.php
1.89 KB
Del
OK
AbstractSyslogHandler.php
3.47 KB
Del
OK
AmqpHandler.php
4.86 KB
Del
OK
BrowserConsoleHandler.php
9.17 KB
Del
OK
BufferHandler.php
4.64 KB
Del
OK
ChromePHPHandler.php
5.1 KB
Del
OK
CouchDBHandler.php
1.96 KB
Del
OK
CubeHandler.php
5.29 KB
Del
OK
Curl
-
Del
OK
DeduplicationHandler.php
5.99 KB
Del
OK
DoctrineCouchDBHandler.php
1.24 KB
Del
OK
DynamoDbHandler.php
2.61 KB
Del
OK
ElasticaHandler.php
3.34 KB
Del
OK
ElasticsearchHandler.php
6.39 KB
Del
OK
ErrorLogHandler.php
2.63 KB
Del
OK
FallbackGroupHandler.php
1.75 KB
Del
OK
FilterHandler.php
6.86 KB
Del
OK
FingersCrossed
-
Del
OK
FingersCrossedHandler.php
8.46 KB
Del
OK
FirePHPHandler.php
5.15 KB
Del
OK
FleepHookHandler.php
3.42 KB
Del
OK
FlowdockHandler.php
3.5 KB
Del
OK
FormattableHandlerInterface.php
901 B
Del
OK
FormattableHandlerTrait.php
1.33 KB
Del
OK
GelfHandler.php
1.5 KB
Del
OK
GroupHandler.php
3.23 KB
Del
OK
Handler.php
1.24 KB
Del
OK
HandlerInterface.php
2.99 KB
Del
OK
HandlerWrapper.php
3.35 KB
Del
OK
IFTTTHandler.php
2.15 KB
Del
OK
InsightOpsHandler.php
1.9 KB
Del
OK
LogEntriesHandler.php
1.75 KB
Del
OK
LogglyHandler.php
4.1 KB
Del
OK
LogmaticHandler.php
2.57 KB
Del
OK
MailHandler.php
2.36 KB
Del
OK
MandrillHandler.php
2.48 KB
Del
OK
MissingExtensionException.php
502 B
Del
OK
MongoDBHandler.php
2.77 KB
Del
OK
NativeMailerHandler.php
4.92 KB
Del
OK
NewRelicHandler.php
6.14 KB
Del
OK
NoopHandler.php
910 B
Del
OK
NullHandler.php
1.39 KB
Del
OK
OverflowHandler.php
4.4 KB
Del
OK
PHPConsoleHandler.php
10.52 KB
Del
OK
ProcessHandler.php
5.07 KB
Del
OK
ProcessableHandlerInterface.php
1.22 KB
Del
OK
ProcessableHandlerTrait.php
1.77 KB
Del
OK
PsrHandler.php
2.49 KB
Del
OK
PushoverHandler.php
7.57 KB
Del
OK
RedisHandler.php
3.06 KB
Del
OK
RedisPubSubHandler.php
1.91 KB
Del
OK
RollbarHandler.php
3.26 KB
Del
OK
RotatingFileHandler.php
6.31 KB
Del
OK
SamplingHandler.php
4.29 KB
Del
OK
SendGridHandler.php
2.86 KB
Del
OK
Slack
-
Del
OK
SlackHandler.php
6.65 KB
Del
OK
SlackWebhookHandler.php
3.73 KB
Del
OK
SocketHandler.php
11.96 KB
Del
OK
SqsHandler.php
1.78 KB
Del
OK
StreamHandler.php
8.22 KB
Del
OK
SwiftMailerHandler.php
3.8 KB
Del
OK
SymfonyMailerHandler.php
3.63 KB
Del
OK
SyslogHandler.php
1.95 KB
Del
OK
SyslogUdp
-
Del
OK
SyslogUdpHandler.php
4.37 KB
Del
OK
TelegramBotHandler.php
8.08 KB
Del
OK
TestHandler.php
6.67 KB
Del
OK
WebRequestRecognizerTrait.php
553 B
Del
OK
WhatFailureGroupHandler.php
1.93 KB
Del
OK
ZendMonitorHandler.php
3.21 KB
Del
OK
Edit: DeduplicationHandler.php
<?php declare (strict_types=1); /* * This file is part of the Monolog package. * * (c) Jordi Boggiano <j.boggiano@seld.be> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Google\Site_Kit_Dependencies\Monolog\Handler; use Google\Site_Kit_Dependencies\Monolog\Logger; use Google\Site_Kit_Dependencies\Psr\Log\LogLevel; /** * Simple handler wrapper that deduplicates log records across multiple requests * * It also includes the BufferHandler functionality and will buffer * all messages until the end of the request or flush() is called. * * This works by storing all log records' messages above $deduplicationLevel * to the file specified by $deduplicationStore. When further logs come in at the end of the * request (or when flush() is called), all those above $deduplicationLevel are checked * against the existing stored logs. If they match and the timestamps in the stored log is * not older than $time seconds, the new log record is discarded. If no log record is new, the * whole data set is discarded. * * This is mainly useful in combination with Mail handlers or things like Slack or HipChat handlers * that send messages to people, to avoid spamming with the same message over and over in case of * a major component failure like a database server being down which makes all requests fail in the * same way. * * @author Jordi Boggiano <j.boggiano@seld.be> * * @phpstan-import-type Record from \Monolog\Logger * @phpstan-import-type LevelName from \Monolog\Logger * @phpstan-import-type Level from \Monolog\Logger */ class DeduplicationHandler extends BufferHandler { /** * @var string */ protected $deduplicationStore; /** * @var Level */ protected $deduplicationLevel; /** * @var int */ protected $time; /** * @var bool */ private $gc = \false; /** * @param HandlerInterface $handler Handler. * @param string $deduplicationStore The file/path where the deduplication log should be kept * @param string|int $deduplicationLevel The minimum logging level for log records to be looked at for deduplication purposes * @param int $time The period (in seconds) during which duplicate entries should be suppressed after a given log is sent through * @param bool $bubble Whether the messages that are handled can bubble up the stack or not * * @phpstan-param Level|LevelName|LogLevel::* $deduplicationLevel */ public function __construct(HandlerInterface $handler, ?string $deduplicationStore = null, $deduplicationLevel = Logger::ERROR, int $time = 60, bool $bubble = \true) { parent::__construct($handler, 0, Logger::DEBUG, $bubble, \false); $this->deduplicationStore = $deduplicationStore === null ? sys_get_temp_dir() . '/monolog-dedup-' . substr(md5(__FILE__), 0, 20) . '.log' : $deduplicationStore; $this->deduplicationLevel = Logger::toMonologLevel($deduplicationLevel); $this->time = $time; } public function flush(): void { if ($this->bufferSize === 0) { return; } $passthru = null; foreach ($this->buffer as $record) { if ($record['level'] >= $this->deduplicationLevel) { $passthru = $passthru || !$this->isDuplicate($record); if ($passthru) { $this->appendRecord($record); } } } // default of null is valid as well as if no record matches duplicationLevel we just pass through if ($passthru === \true || $passthru === null) { $this->handler->handleBatch($this->buffer); } $this->clear(); if ($this->gc) { $this->collectLogs(); } } /** * @phpstan-param Record $record */ private function isDuplicate(array $record): bool { if (!file_exists($this->deduplicationStore)) { return \false; } $store = file($this->deduplicationStore, \FILE_IGNORE_NEW_LINES | \FILE_SKIP_EMPTY_LINES); if (!is_array($store)) { return \false; } $yesterday = time() - 86400; $timestampValidity = $record['datetime']->getTimestamp() - $this->time; $expectedMessage = preg_replace('{[\r\n].*}', '', $record['message']); for ($i = count($store) - 1; $i >= 0; $i--) { list($timestamp, $level, $message) = explode(':', $store[$i], 3); if ($level === $record['level_name'] && $message === $expectedMessage && $timestamp > $timestampValidity) { return \true; } if ($timestamp < $yesterday) { $this->gc = \true; } } return \false; } private function collectLogs(): void { if (!file_exists($this->deduplicationStore)) { return; } $handle = fopen($this->deduplicationStore, 'rw+'); if (!$handle) { throw new \RuntimeException('Failed to open file for reading and writing: ' . $this->deduplicationStore); } flock($handle, \LOCK_EX); $validLogs = []; $timestampValidity = time() - $this->time; while (!feof($handle)) { $log = fgets($handle); if ($log && substr($log, 0, 10) >= $timestampValidity) { $validLogs[] = $log; } } ftruncate($handle, 0); rewind($handle); foreach ($validLogs as $log) { fwrite($handle, $log); } flock($handle, \LOCK_UN); fclose($handle); $this->gc = \false; } /** * @phpstan-param Record $record */ private function appendRecord(array $record): void { file_put_contents($this->deduplicationStore, $record['datetime']->getTimestamp() . ':' . $record['level_name'] . ':' . preg_replace('{[\r\n].*}', '', $record['message']) . "\n", \FILE_APPEND); } }
Save