OXIESEC PANEL
- Current Dir:
/
/
var
/
www
/
firebase
/
vendor
/
monolog
/
monolog
/
src
/
Monolog
/
Handler
Server IP: 139.59.38.164
Upload:
Create Dir:
Name
Size
Modified
Perms
📁
..
-
08/12/2024 10:35:58 AM
rwxr-xr-x
📄
AbstractHandler.php
2.71 KB
08/12/2024 10:35:56 AM
rw-r--r--
📄
AbstractProcessingHandler.php
1.52 KB
08/12/2024 10:35:56 AM
rw-r--r--
📄
AbstractSyslogHandler.php
3.24 KB
08/12/2024 10:35:56 AM
rw-r--r--
📄
AmqpHandler.php
5.12 KB
08/12/2024 10:35:56 AM
rw-r--r--
📄
BrowserConsoleHandler.php
9.3 KB
08/12/2024 10:35:56 AM
rw-r--r--
📄
BufferHandler.php
4.6 KB
08/12/2024 10:35:56 AM
rw-r--r--
📄
ChromePHPHandler.php
5.21 KB
08/12/2024 10:35:56 AM
rw-r--r--
📄
CouchDBHandler.php
2.64 KB
08/12/2024 10:35:56 AM
rw-r--r--
📄
CubeHandler.php
5.48 KB
08/12/2024 10:35:56 AM
rw-r--r--
📁
Curl
-
08/12/2024 10:36:32 AM
rwxr-xr-x
📄
DeduplicationHandler.php
6.42 KB
08/12/2024 10:35:56 AM
rw-r--r--
📄
DoctrineCouchDBHandler.php
1.17 KB
08/12/2024 10:35:56 AM
rw-r--r--
📄
DynamoDbHandler.php
1.97 KB
08/12/2024 10:35:56 AM
rw-r--r--
📄
ElasticaHandler.php
3.72 KB
08/12/2024 10:35:56 AM
rw-r--r--
📄
ElasticsearchHandler.php
7.01 KB
08/12/2024 10:35:56 AM
rw-r--r--
📄
ErrorLogHandler.php
2.71 KB
08/12/2024 10:35:56 AM
rw-r--r--
📄
FallbackGroupHandler.php
1.75 KB
08/12/2024 10:35:56 AM
rw-r--r--
📄
FilterHandler.php
7.12 KB
08/12/2024 10:35:57 AM
rw-r--r--
📁
FingersCrossed
-
08/12/2024 10:36:32 AM
rwxr-xr-x
📄
FingersCrossedHandler.php
8.21 KB
08/12/2024 10:35:57 AM
rw-r--r--
📄
FirePHPHandler.php
5.2 KB
08/12/2024 10:35:57 AM
rw-r--r--
📄
FleepHookHandler.php
3.57 KB
08/12/2024 10:35:57 AM
rw-r--r--
📄
FlowdockHandler.php
3.52 KB
08/12/2024 10:35:57 AM
rw-r--r--
📄
FormattableHandlerInterface.php
791 bytes
08/12/2024 10:35:57 AM
rw-r--r--
📄
FormattableHandlerTrait.php
1.29 KB
08/12/2024 10:35:57 AM
rw-r--r--
📄
GelfHandler.php
1.48 KB
08/12/2024 10:35:57 AM
rw-r--r--
📄
GroupHandler.php
3.32 KB
08/12/2024 10:35:57 AM
rw-r--r--
📄
Handler.php
1.27 KB
08/12/2024 10:35:57 AM
rw-r--r--
📄
HandlerInterface.php
2.79 KB
08/12/2024 10:35:57 AM
rw-r--r--
📄
HandlerWrapper.php
3.41 KB
08/12/2024 10:35:57 AM
rw-r--r--
📄
IFTTTHandler.php
2.29 KB
08/12/2024 10:35:57 AM
rw-r--r--
📄
InsightOpsHandler.php
2.11 KB
08/12/2024 10:35:57 AM
rw-r--r--
📄
LogEntriesHandler.php
1.93 KB
08/12/2024 10:35:57 AM
rw-r--r--
📄
LogglyHandler.php
4.17 KB
08/12/2024 10:35:57 AM
rw-r--r--
📄
LogmaticHandler.php
2.67 KB
08/12/2024 10:35:57 AM
rw-r--r--
📄
MailHandler.php
2.28 KB
08/12/2024 10:35:57 AM
rw-r--r--
📄
MandrillHandler.php
2.56 KB
08/12/2024 10:35:57 AM
rw-r--r--
📄
MissingExtensionException.php
494 bytes
08/12/2024 10:35:57 AM
rw-r--r--
📄
MongoDBHandler.php
2.39 KB
08/12/2024 10:35:57 AM
rw-r--r--
📄
NativeMailerHandler.php
5.05 KB
08/12/2024 10:35:57 AM
rw-r--r--
📄
NewRelicHandler.php
5.88 KB
08/12/2024 10:35:57 AM
rw-r--r--
📄
NoopHandler.php
950 bytes
08/12/2024 10:35:57 AM
rw-r--r--
📄
NullHandler.php
1.35 KB
08/12/2024 10:35:57 AM
rw-r--r--
📄
OverflowHandler.php
4.35 KB
08/12/2024 10:35:57 AM
rw-r--r--
📄
PHPConsoleHandler.php
12.22 KB
08/12/2024 10:35:57 AM
rw-r--r--
📄
ProcessHandler.php
5.24 KB
08/12/2024 10:35:57 AM
rw-r--r--
📄
ProcessableHandlerInterface.php
1.2 KB
08/12/2024 10:35:57 AM
rw-r--r--
📄
ProcessableHandlerTrait.php
1.65 KB
08/12/2024 10:35:57 AM
rw-r--r--
📄
PsrHandler.php
2.5 KB
08/12/2024 10:35:57 AM
rw-r--r--
📄
PushoverHandler.php
8.16 KB
08/12/2024 10:35:57 AM
rw-r--r--
📄
RedisHandler.php
2.76 KB
08/12/2024 10:35:57 AM
rw-r--r--
📄
RedisPubSubHandler.php
1.71 KB
08/12/2024 10:35:57 AM
rw-r--r--
📄
RollbarHandler.php
3.65 KB
08/12/2024 10:35:57 AM
rw-r--r--
📄
RotatingFileHandler.php
7.02 KB
08/12/2024 10:35:57 AM
rw-r--r--
📄
SamplingHandler.php
3.94 KB
08/12/2024 10:35:57 AM
rw-r--r--
📄
SendGridHandler.php
2.97 KB
08/12/2024 10:35:57 AM
rw-r--r--
📁
Slack
-
08/12/2024 10:36:32 AM
rwxr-xr-x
📄
SlackHandler.php
7.25 KB
08/12/2024 10:35:57 AM
rw-r--r--
📄
SlackWebhookHandler.php
3.92 KB
08/12/2024 10:35:57 AM
rw-r--r--
📄
SocketHandler.php
12.27 KB
08/12/2024 10:35:57 AM
rw-r--r--
📄
SqsHandler.php
1.77 KB
08/12/2024 10:35:57 AM
rw-r--r--
📄
StreamHandler.php
6.83 KB
08/12/2024 10:35:57 AM
rw-r--r--
📄
SymfonyMailerHandler.php
3.55 KB
08/12/2024 10:35:57 AM
rw-r--r--
📄
SyslogHandler.php
1.71 KB
08/12/2024 10:35:57 AM
rw-r--r--
📁
SyslogUdp
-
08/12/2024 10:36:32 AM
rwxr-xr-x
📄
SyslogUdpHandler.php
4.78 KB
08/12/2024 10:35:57 AM
rw-r--r--
📄
TelegramBotHandler.php
9.51 KB
08/12/2024 10:35:57 AM
rw-r--r--
📄
TestHandler.php
6.51 KB
08/12/2024 10:35:57 AM
rw-r--r--
📄
WebRequestRecognizerTrait.php
527 bytes
08/12/2024 10:35:57 AM
rw-r--r--
📄
WhatFailureGroupHandler.php
1.94 KB
08/12/2024 10:35:57 AM
rw-r--r--
📄
ZendMonitorHandler.php
2.87 KB
08/12/2024 10:35:57 AM
rw-r--r--
Editing: ElasticsearchHandler.php
Close
<?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 Monolog\Handler; use Elastic\Elasticsearch\Response\Elasticsearch; use Throwable; use RuntimeException; use Monolog\Level; use Monolog\Formatter\FormatterInterface; use Monolog\Formatter\ElasticsearchFormatter; use InvalidArgumentException; use Elasticsearch\Common\Exceptions\RuntimeException as ElasticsearchRuntimeException; use Elasticsearch\Client; use Monolog\LogRecord; use Elastic\Elasticsearch\Exception\InvalidArgumentException as ElasticInvalidArgumentException; use Elastic\Elasticsearch\Client as Client8; /** * Elasticsearch handler * * @link https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/index.html * * Simple usage example: * * $client = \Elasticsearch\ClientBuilder::create() * ->setHosts($hosts) * ->build(); * * $options = array( * 'index' => 'elastic_index_name', * 'type' => 'elastic_doc_type', * ); * $handler = new ElasticsearchHandler($client, $options); * $log = new Logger('application'); * $log->pushHandler($handler); * * @author Avtandil Kikabidze <akalongman@gmail.com> * @phpstan-type Options array{ * index: string, * type: string, * ignore_error: bool, * op_type: 'index'|'create' * } * @phpstan-type InputOptions array{ * index?: string, * type?: string, * ignore_error?: bool, * op_type?: 'index'|'create' * } */ class ElasticsearchHandler extends AbstractProcessingHandler { protected Client|Client8 $client; /** * @var mixed[] Handler config options * @phpstan-var Options */ protected array $options; /** * @var bool */ private $needsType; /** * @param Client|Client8 $client Elasticsearch Client object * @param mixed[] $options Handler configuration * * @phpstan-param InputOptions $options */ public function __construct(Client|Client8 $client, array $options = [], int|string|Level $level = Level::Debug, bool $bubble = true) { parent::__construct($level, $bubble); $this->client = $client; $this->options = array_merge( [ 'index' => 'monolog', // Elastic index name 'type' => '_doc', // Elastic document type 'ignore_error' => false, // Suppress Elasticsearch exceptions 'op_type' => 'index', // Elastic op_type (index or create) (https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-index_.html#docs-index-api-op_type) ], $options ); if ($client instanceof Client8 || $client::VERSION[0] === '7') { $this->needsType = false; // force the type to _doc for ES8/ES7 $this->options['type'] = '_doc'; } else { $this->needsType = true; } } /** * @inheritDoc */ protected function write(LogRecord $record): void { $this->bulkSend([$record->formatted]); } /** * @inheritDoc */ public function setFormatter(FormatterInterface $formatter): HandlerInterface { if ($formatter instanceof ElasticsearchFormatter) { return parent::setFormatter($formatter); } throw new InvalidArgumentException('ElasticsearchHandler is only compatible with ElasticsearchFormatter'); } /** * Getter options * * @return mixed[] * * @phpstan-return Options */ public function getOptions(): array { return $this->options; } /** * @inheritDoc */ protected function getDefaultFormatter(): FormatterInterface { return new ElasticsearchFormatter($this->options['index'], $this->options['type']); } /** * @inheritDoc */ public function handleBatch(array $records): void { $documents = $this->getFormatter()->formatBatch($records); $this->bulkSend($documents); } /** * Use Elasticsearch bulk API to send list of documents * * @param array<array<mixed>> $records Records + _index/_type keys * @throws \RuntimeException */ protected function bulkSend(array $records): void { try { $params = [ 'body' => [], ]; foreach ($records as $record) { $params['body'][] = [ $this->options['op_type'] => $this->needsType ? [ '_index' => $record['_index'], '_type' => $record['_type'], ] : [ '_index' => $record['_index'], ], ]; unset($record['_index'], $record['_type']); $params['body'][] = $record; } /** @var Elasticsearch */ $responses = $this->client->bulk($params); if ($responses['errors'] === true) { throw $this->createExceptionFromResponses($responses); } } catch (Throwable $e) { if (! $this->options['ignore_error']) { throw new RuntimeException('Error sending messages to Elasticsearch', 0, $e); } } } /** * Creates elasticsearch exception from responses array * * Only the first error is converted into an exception. * * @param mixed[]|Elasticsearch $responses returned by $this->client->bulk() */ protected function createExceptionFromResponses($responses): Throwable { foreach ($responses['items'] ?? [] as $item) { if (isset($item['index']['error'])) { return $this->createExceptionFromError($item['index']['error']); } } if (class_exists(ElasticInvalidArgumentException::class)) { return new ElasticInvalidArgumentException('Elasticsearch failed to index one or more records.'); } return new ElasticsearchRuntimeException('Elasticsearch failed to index one or more records.'); } /** * Creates elasticsearch exception from error array * * @param mixed[] $error */ protected function createExceptionFromError(array $error): Throwable { $previous = isset($error['caused_by']) ? $this->createExceptionFromError($error['caused_by']) : null; if (class_exists(ElasticInvalidArgumentException::class)) { return new ElasticInvalidArgumentException($error['type'] . ': ' . $error['reason'], 0, $previous); } return new ElasticsearchRuntimeException($error['type'] . ': ' . $error['reason'], 0, $previous); } }