Compare commits

..

No commits in common. 'production' and '0.2.1' have entirely different histories.

@ -7,6 +7,7 @@ use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException; use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Exception\GuzzleException; use GuzzleHttp\Exception\GuzzleException;
use Monolog\Handler\AbstractProcessingHandler; use Monolog\Handler\AbstractProcessingHandler;
use Monolog\Logger;
use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ResponseInterface;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Monolog\LogRecord; use Monolog\LogRecord;
@ -32,10 +33,10 @@ class DiscordHandler extends AbstractProcessingHandler
/** /**
* @param string $webhook * @param string $webhook
* @param mixed $level * @param int $level
* @param bool $bubble * @param bool $bubble
*/ */
public function __construct(string $webhook, $level = 400, bool $bubble = true) public function __construct(string $webhook, \Monolog\Level $level = \Monolog\Level::ERROR, bool $bubble = true)
{ {
$this->webhook = $webhook; $this->webhook = $webhook;
$this->client = new Client(); $this->client = new Client();
@ -44,35 +45,18 @@ class DiscordHandler extends AbstractProcessingHandler
} }
/** /**
* @param mixed $record * @param LogRecord $record
* @return void * @return void
* @throws GuzzleException * @throws GuzzleException
*/ */
protected function write($record): void protected function write(LogRecord $record): void
{
if (is_array($record)) {
// Implementação para Monolog 1.x
$this->recordHandler($record);
}elseif (class_exists(LogRecord::class) && $record instanceof LogRecord) {
// Implementação para Monolog 2.x
$arrayRecord = $record->toArray();
$this->recordHandler($arrayRecord);
}
}
/**
* @param array $record
* @return void
* @throws GuzzleException
*/
protected function recordHandler(array $record)
{ {
if ($this->rateLimitRemaining === 0 && $this->rateLimitReset !== null) { if ($this->rateLimitRemaining === 0 && $this->rateLimitReset !== null) {
$this->waitUntil($this->rateLimitReset); $this->waitUntil($this->rateLimitReset);
} }
try { try {
$response = $this->send($record); $response = $this->send($record->toArray());
} catch (ClientException $exception) { } catch (ClientException $exception) {
$response = $exception->getResponse(); $response = $exception->getResponse();
@ -83,7 +67,7 @@ class DiscordHandler extends AbstractProcessingHandler
$retryAfter = $response->getHeaderLine('Retry-After'); $retryAfter = $response->getHeaderLine('Retry-After');
$this->wait((int)$retryAfter); $this->wait((int)$retryAfter);
$this->send($record); $this->send($record->toArray());
} }
$this->rateLimitRemaining = (int)$response->getHeaderLine('X-RateLimit-Remaining'); $this->rateLimitRemaining = (int)$response->getHeaderLine('X-RateLimit-Remaining');

@ -32,7 +32,7 @@ class RabbitMQHandler extends AbstractProcessingHandler
/** /**
* @throws Exception * @throws Exception
*/ */
public function __construct($exchange = 'logs', $routingKey = 'log', $level = 400, $bubble = true) public function __construct($exchange = 'logs', $routingKey = 'log', $level = \Monolog\Level::ERROR, $bubble = true)
{ {
parent::__construct($level, $bubble); parent::__construct($level, $bubble);
@ -54,30 +54,14 @@ class RabbitMQHandler extends AbstractProcessingHandler
} }
/** /**
* @param mixed $record * @param LogRecord $record
* @return void * @return void
*/ */
public function write($record): void public function write(LogRecord $record): void
{ {
if (is_array($record)) { $data = json_encode($record->toArray());
// Implementação para Monolog 1.x
$this->recordHandler($record);
}elseif (class_exists(LogRecord::class) && $record instanceof LogRecord) {
// Implementação para Monolog 2.x
$arrayRecord = $record->toArray();
$this->recordHandler($arrayRecord);
}
}
/**
* @param array $record
* @return void
*/
protected function recordHandler(array $record)
{
$data = json_encode($record);
$msg = new AMQPMessage($data, [ $msg = new AMQPMessage($data, [
'delivery_mode' => 2 'delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT
]); ]);
$this->channel->basic_publish($msg, $this->exchange, $this->routingKey); $this->channel->basic_publish($msg, $this->exchange, $this->routingKey);

@ -69,8 +69,6 @@ trait LogTrait
{ {
$this->initializeLogServices(); $this->initializeLogServices();
$customData['server_ip'] = config('laravel-logs-layer.server_ip');
foreach ($this->logServices as $logService) { foreach ($this->logServices as $logService) {
$logService->$method($message, [ $logService->$method($message, [
'custom_data' => $customData, 'custom_data' => $customData,
@ -149,8 +147,6 @@ trait LogTrait
$this->initializeLogServices(); $this->initializeLogServices();
$customData['server_ip'] = config('laravel-logs-layer.server_ip');
foreach ($this->logServices as $logService) { foreach ($this->logServices as $logService) {
$logService->$log_level($caller, $exception, ExceptionContextDTO::fromArray([ $logService->$log_level($caller, $exception, ExceptionContextDTO::fromArray([
'code' => $errorCode, 'code' => $errorCode,

@ -15,5 +15,4 @@ return [
'backoff' => explode(',', env('LOG_QUEUE_BACKOFF', '15')) 'backoff' => explode(',', env('LOG_QUEUE_BACKOFF', '15'))
], ],
'sensitive_data' => env('LOGS_LAYER_SENSITIVE_DATA', 'password,password_confirmation,token,api_token,api_key,access_token,refresh_token,authorization_code,client_secret'), 'sensitive_data' => env('LOGS_LAYER_SENSITIVE_DATA', 'password,password_confirmation,token,api_token,api_key,access_token,refresh_token,authorization_code,client_secret'),
'server_ip' => env('SERVER_IP', '127.0.0.1')
]; ];

Loading…
Cancel
Save