Skip to content

Commit 1ce9be2

Browse files
Merge pull request #1 from nuwber/hypervel-migration
Hypervel migration
2 parents aea6388 + acaffd3 commit 1ce9be2

15 files changed

Lines changed: 188 additions & 283 deletions

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
uses: shivammathur/setup-php@v2
1515
with:
1616
php-version: ${{ matrix.php-versions }}
17-
extensions: mbstring,bcmath
17+
extensions: mbstring,bcmath,swoole
1818
tools: composer
1919
- name: Install dependencies
2020
run: composer install --quiet --no-ansi --no-interaction --no-scripts --no-progress

README.md

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,8 @@
1-
# Laravel Gelf Logger
2-
3-
[![Build Status](https://github.com/hedii/laravel-gelf-logger/workflows/Tests/badge.svg)](https://github.com/hedii/laravel-gelf-logger/actions)
4-
[![Total Downloads](https://poser.pugx.org/hedii/laravel-gelf-logger/downloads)](//packagist.org/packages/hedii/laravel-gelf-logger)
5-
[![License](https://poser.pugx.org/hedii/laravel-gelf-logger/license)](//packagist.org/packages/hedii/laravel-gelf-logger)
6-
[![Latest Stable Version](https://poser.pugx.org/hedii/laravel-gelf-logger/v)](//packagist.org/packages/hedii/laravel-gelf-logger)
7-
8-
| **Laravel** | **laravel-gelf-logger** |
9-
|-------------|-------------------------|
10-
| 5.6 | ^3.0 |
11-
| 5.8 | ^3.1 |
12-
| 6.0 | ^4.0 |
13-
| 7.0 | ^5.0 |
14-
| 8.0 | ^5.3 |
15-
| 8.0 | ^6.0 (with php 8) |
16-
| 9.0 | ^7.0 |
17-
| 10.0 | ^8.0 |
18-
| 11.0 | ^9.0 |
19-
| 12.0 | ^10.0 |
20-
21-
A package to send [gelf](http://docs.graylog.org/en/2.1/pages/gelf.html) logs to a gelf compatible backend like graylog. It is a Laravel wrapper for [bzikarsky/gelf-php](https://github.com/bzikarsky/gelf-php) package.
22-
23-
It uses the new [Laravel custom log channel](https://laravel.com/docs/master/logging) introduced in Laravel 5.6.
1+
# Hypervel Gelf Logger
2+
3+
A package to send [gelf](http://docs.graylog.org/en/2.1/pages/gelf.html) logs to a gelf compatible backend like graylog. It is a Hypervel wrapper for [bzikarsky/gelf-php](https://github.com/bzikarsky/gelf-php) package.
4+
5+
This package uses Hypervel's custom log channel system.
246

257
A gelf receiver like graylog2 must be configured to receive messages with a GELF UDP, TCP or HTTP Input.
268

@@ -38,7 +20,7 @@ A gelf receiver like graylog2 must be configured to receive messages with a GELF
3820
Install via [composer](https://getcomposer.org/doc/00-intro.md)
3921

4022
```sh
41-
composer require hedii/laravel-gelf-logger
23+
composer require nuwber/hypervel-gelf-logger
4224
```
4325

4426
Edit `config/logging.php` to add the new `gelf` log channel.
@@ -59,7 +41,7 @@ return [
5941
'gelf' => [
6042
'driver' => 'custom',
6143

62-
'via' => \Hedii\LaravelGelfLogger\GelfLoggerFactory::class,
44+
'via' => \Nuwber\HypervelGelfLogger\GelfLoggerFactory::class,
6345

6446
// This optional option determines the processors that should be
6547
// pushed to the handler. This option is useful to modify a field
@@ -68,8 +50,8 @@ return [
6850
// __invoke method: see monolog documentation about processors.
6951
// Default is an empty array.
7052
'processors' => [
71-
\Hedii\LaravelGelfLogger\Processors\NullStringProcessor::class,
72-
\Hedii\LaravelGelfLogger\Processors\RenameIdFieldProcessor::class,
53+
\Nuwber\HypervelGelfLogger\Processors\NullStringProcessor::class,
54+
\Nuwber\HypervelGelfLogger\Processors\RenameIdFieldProcessor::class,
7355
// another processor...
7456
],
7557

@@ -167,7 +149,7 @@ return [
167149

168150
## Usage
169151

170-
Once you have modified the Laravel logging configuration, you can use the gelf log channel [as any Laravel log channel](https://laravel.com/docs/master/logging#writing-log-messages).
152+
Once you have modified the Hypervel logging configuration, you can use the gelf log channel as any Hypervel log channel.
171153

172154
### Example
173155

@@ -192,4 +174,8 @@ composer test
192174

193175
## License
194176

195-
laravel-gelf-logger is released under the MIT Licence. See the bundled [LICENSE](https://github.com/hedii/laravel-gelf-logger/blob/master/LICENSE.md) file for details.
177+
hypervel-gelf-logger is released under the MIT Licence. See the bundled LICENSE file for details.
178+
179+
## Credits
180+
181+
This package is a Hypervel port of [hedii/laravel-gelf-logger](https://github.com/hedii/laravel-gelf-logger).

composer.json

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
{
22
"name": "nuwber/hypervel-gelf-logger",
3-
"description": "A Laravel package to send logs to a gelf compatible backend like graylog",
3+
"description": "A Hypervel package to send logs to a gelf compatible backend like graylog",
44
"type": "library",
55
"license": "MIT",
66
"keywords": [
7-
"hedii",
8-
"laravel-gelf",
7+
"nuwber",
8+
"hypervel",
9+
"hypervel-gelf",
910
"gelf",
1011
"udp",
1112
"log",
1213
"logging",
1314
"graylog",
1415
"graylog2",
15-
"laravel",
1616
"php"
1717
],
1818
"authors": [
@@ -28,19 +28,26 @@
2828
"require": {
2929
"php": "^8.2",
3030
"graylog2/gelf-php": "^2.0",
31-
"illuminate/log": "^12.0"
31+
"hypervel/log": "^0.3.7",
32+
"hypervel/laminas-mime": "^0.1.0"
3233
},
3334
"require-dev": {
34-
"orchestra/testbench": "^10.0"
35+
"hyperf/testing": "^3.1",
36+
"phpunit/phpunit": "^10.0"
3537
},
3638
"autoload": {
3739
"psr-4": {
38-
"Hedii\\LaravelGelfLogger\\": "src/"
40+
"Nuwber\\HypervelGelfLogger\\": "src/"
3941
}
4042
},
4143
"autoload-dev": {
4244
"psr-4": {
43-
"Hedii\\LaravelGelfLogger\\Tests\\": "tests/"
45+
"Nuwber\\HypervelGelfLogger\\Tests\\": "tests/"
46+
}
47+
},
48+
"extra": {
49+
"hyperf": {
50+
"config": "Nuwber\\HypervelGelfLogger\\ConfigProvider"
4451
}
4552
},
4653
"config": {

src/ConfigProvider.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Nuwber\HypervelGelfLogger;
6+
7+
class ConfigProvider
8+
{
9+
public function __invoke(): array
10+
{
11+
return [
12+
'dependencies' => [],
13+
'annotations' => [
14+
'scan' => [
15+
'paths' => [
16+
__DIR__,
17+
],
18+
],
19+
],
20+
];
21+
}
22+
}

src/GelfLoggerFactory.php

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22

3-
namespace Hedii\LaravelGelfLogger;
3+
declare(strict_types=1);
4+
5+
namespace Nuwber\HypervelGelfLogger;
46

57
use Gelf\Publisher;
68
use Gelf\Transport\AbstractTransport;
@@ -9,17 +11,15 @@
911
use Gelf\Transport\SslOptions;
1012
use Gelf\Transport\TcpTransport;
1113
use Gelf\Transport\UdpTransport;
12-
use Illuminate\Contracts\Container\Container;
13-
use Illuminate\Log\ParsesLogConfiguration;
1414
use Monolog\Formatter\GelfMessageFormatter;
1515
use Monolog\Handler\GelfHandler;
16+
use Monolog\Level;
1617
use Monolog\Logger;
18+
use Psr\Container\ContainerInterface;
1719

1820
class GelfLoggerFactory
1921
{
20-
use ParsesLogConfiguration;
21-
22-
public function __construct(protected Container $app)
22+
public function __construct(protected ContainerInterface $container)
2323
{
2424
}
2525

@@ -48,7 +48,7 @@ public function __invoke(array $config): Logger
4848
$transport = new IgnoreErrorTransportWrapper($transport);
4949
}
5050

51-
$handler = new GelfHandler(new Publisher($transport), $this->level($config));
51+
$handler = new GelfHandler(new Publisher($transport), $this->parseLevel($config));
5252

5353
$handler->setFormatter(
5454
new GelfMessageFormatter(
@@ -63,7 +63,7 @@ public function __invoke(array $config): Logger
6363
$handler->pushProcessor(new $processor);
6464
}
6565

66-
return new Logger($this->parseChannel($config), [$handler]);
66+
return new Logger($this->parseChannelName($config), [$handler]);
6767
}
6868

6969
protected function parseConfig(array $config): array
@@ -89,7 +89,7 @@ protected function parseConfig(array $config): array
8989
$config['ssl_options']['allow_self_signed'] ??= false;
9090
}
9191

92-
if ($config['http_basic_auth']) {
92+
if ($config['http_basic_auth'] && is_array($config['http_basic_auth'])) {
9393
$config['http_basic_auth']['username'] ??= null;
9494
$config['http_basic_auth']['password'] ??= null;
9595
}
@@ -142,10 +142,10 @@ protected function sslOptions(?array $sslConfig = null): SslOptions
142142
protected function enableBasicAuthentication(AbstractTransport $transport, array $config): bool
143143
{
144144
return $transport instanceof HttpTransport
145-
&& $config['http_basic_auth']
146-
&& $config['http_basic_auth']['username']
147-
&& $config['http_basic_auth']['password'];
148-
145+
&& isset($config['http_basic_auth'])
146+
&& is_array($config['http_basic_auth'])
147+
&& !empty($config['http_basic_auth']['username'])
148+
&& !empty($config['http_basic_auth']['password']);
149149
}
150150

151151
protected function parseProcessors(array $config): array
@@ -163,6 +163,24 @@ protected function parseProcessors(array $config): array
163163

164164
protected function getFallbackChannelName(): string
165165
{
166-
return $this->app->bound('env') ? $this->app->environment() : 'production';
166+
return $this->container->has('env')
167+
? $this->container->get('env')
168+
: 'production';
169+
}
170+
171+
protected function parseLevel(array $config): Level
172+
{
173+
$level = $config['level'] ?? 'debug';
174+
175+
if ($level instanceof Level) {
176+
return $level;
177+
}
178+
179+
return Level::fromName(ucfirst(strtolower($level)));
180+
}
181+
182+
protected function parseChannelName(array $config): string
183+
{
184+
return $config['name'] ?? $this->getFallbackChannelName();
167185
}
168186
}

src/Processors/NullStringProcessor.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22

3-
namespace Hedii\LaravelGelfLogger\Processors;
3+
declare(strict_types=1);
4+
5+
namespace Nuwber\HypervelGelfLogger\Processors;
46

57
use Monolog\LogRecord;
68
use Monolog\Processor\ProcessorInterface;

src/Processors/RenameIdFieldProcessor.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22

3-
namespace Hedii\LaravelGelfLogger\Processors;
3+
declare(strict_types=1);
4+
5+
namespace Nuwber\HypervelGelfLogger\Processors;
46

57
use Monolog\LogRecord;
68
use Monolog\Processor\ProcessorInterface;

tests/Fake/AnotherTestProcessor.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22

3-
namespace Hedii\LaravelGelfLogger\Tests\Fake;
3+
declare(strict_types=1);
4+
5+
namespace Nuwber\HypervelGelfLogger\Tests\Fake;
46

57
use Monolog\LogRecord;
68

tests/Fake/TestProcessor.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22

3-
namespace Hedii\LaravelGelfLogger\Tests\Fake;
3+
declare(strict_types=1);
4+
5+
namespace Nuwber\HypervelGelfLogger\Tests\Fake;
46

57
use Monolog\LogRecord;
68

0 commit comments

Comments
 (0)