Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(deps): add Laravel 10 support #17

Merged
merged 5 commits into from
Mar 9, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@
"illuminate/contracts": "^9.0|^10.0",
"illuminate/log": "^9.0|^10.0",
"illuminate/support": "^9.0|^10.0",
"monolog/monolog": "^1.24|^2.0"
"monolog/monolog": "^2.0|^3.3"
},
"require-dev": {
"ext-sockets": "*",
"ext-zlib": "*",
"exolnet/phpcs-config": "^2.0",
"laravel/pint": "^1.2",
"mockery/mockery": "^1.4",
Expand Down
2 changes: 1 addition & 1 deletion src/GraylogServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function register()
'handler' => GraylogHandler::class,
'handler_with' => [
'transport' => 'udp',
'host' => 'localhost',
'host' => '127.0.0.1',
'port' => 12201,
'path' => '/gelf',
'extra' => [
Expand Down
1 change: 0 additions & 1 deletion src/Handler/GraylogHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class GraylogHandler extends GelfHandler
{
/**
* @param string $transport
* @param bool $secure
* @param string $host
* @param int $port
* @param string $path
Expand Down
9 changes: 5 additions & 4 deletions src/Processor/ExtraProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,28 @@

namespace Exolnet\Graylog\Processor;

use Monolog\LogRecord;
use Monolog\Processor\ProcessorInterface;

class ExtraProcessor implements ProcessorInterface
{
/**
* @var array
* @var array|\Monolog\LogRecord
*/
protected $config;
protected array|LogRecord $config;

/**
* @param array $config
*/
public function __construct(array $config)
public function __construct(array|LogRecord $config)
{
$this->config = $config;
}

/**
* {@inheritDoc}
*/
public function __invoke(array $record)
public function __invoke(array|LogRecord $record)
{
foreach ($this->config as $extraKey => $extra) {
$record['extra'][$extraKey] = $extra;
Expand Down
3 changes: 2 additions & 1 deletion src/Processor/LaravelProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Request;
use Illuminate\Support\Str;
use Monolog\LogRecord;
use Monolog\Processor\ProcessorInterface;

class LaravelProcessor implements ProcessorInterface
{
/**
* {@inheritDoc}
*/
public function __invoke(array $record)
public function __invoke(array|LogRecord $record)
{
$record['extra']['level_name'] = $record['level_name'];
$record['extra']['app'] = Str::slug(Config::get('app.name'));
Expand Down
24 changes: 24 additions & 0 deletions tests/Feature/GraylogDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,28 @@ public function testUseGraylogHandler(): void

$this->assertInstanceOf(GraylogHandler::class, $handlers[0] ?? null);
}

/**
* @return void
* @test
*/
public function testLogging(): void
{
$socket = socket_create(AF_INET, SOCK_DGRAM, 0);
socket_bind($socket, '127.0.0.1', 12201);

$this->channel->info('Test message');

socket_recvfrom($socket, $buffer, 1024, 0, $remoteIp, $remotePort);

$json = json_decode(gzuncompress($buffer), true);

$this->assertEquals('1.0', $json['version']);
$this->assertEquals('Test message', $json['short_message']);
$this->assertEquals(6, $json['level']);
$this->assertEquals('laravel', $json['_app']);
$this->assertEquals('INFO', $json['_level_name']);
$this->assertEquals('testing', $json['_env']);
$this->assertEquals('Symfony', $json['_user_agent']);
}
}