Skip to content

Commit bf4b769

Browse files
committed
Laravel 10 support
1 parent fbdec3e commit bf4b769

File tree

13 files changed

+123
-126
lines changed

13 files changed

+123
-126
lines changed

Diff for: .github/workflows/tests.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
strategy:
1818
fail-fast: false
1919
matrix:
20-
php: [8.0, 8.1]
20+
php: [8.1, 8.2]
2121
stability: [prefer-lowest, prefer-stable]
2222

2323
name: PHP ${{ matrix.php }} / ${{ matrix.stability }}
@@ -47,7 +47,7 @@ jobs:
4747
command: composer update --prefer-dist --${{ matrix.stability }} --no-interaction --no-progress --ansi
4848

4949
- name: Run tests
50-
run: vendor/bin/phpunit --verbose --colors=always --coverage-clover ./build/logs/clover.xml
50+
run: vendor/bin/phpunit --colors=always --coverage-clover ./build/logs/clover.xml
5151
env:
5252
DB_USERNAME: root
5353
DB_PASSWORD: root

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/.idea
2+
/.phpunit.cache
23
/.vscode
34
/vendor
45
.DS_Store

Diff for: README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
[<img src="https://user-images.githubusercontent.com/1286821/181085373-12eee197-187a-4438-90fe-571ac6d68900.png" alt="Buy me a coffee" width="200" />](https://buymeacoffee.com/dmitry.ivanov)
66

77
[![StyleCI](https://github.styleci.io/repos/61117768/shield?branch=master&style=flat)](https://github.styleci.io/repos/61117768?branch=master)
8-
[![Build Status](https://img.shields.io/github/workflow/status/dmitry-ivanov/laravel-console-logger/tests/master)](https://github.com/dmitry-ivanov/laravel-console-logger/actions?query=workflow%3Atests+branch%3Amaster)
9-
[![Coverage Status](https://img.shields.io/codecov/c/github/dmitry-ivanov/laravel-console-logger/master)](https://app.codecov.io/gh/dmitry-ivanov/laravel-console-logger/branch/master)
8+
[![Build Status](https://img.shields.io/github/actions/workflow/status/dmitry-ivanov/laravel-console-logger/tests.yml?branch=master)](https://github.com/dmitry-ivanov/laravel-console-logger/actions?query=workflow%3Atests+branch%3Amaster)
9+
[![Coverage Status](https://img.shields.io/codecov/c/github/dmitry-ivanov/laravel-console-logger/master)](https://app.codecov.io/gh/dmitry-ivanov/laravel-console-logger/tree/master)
1010

1111
![Packagist Version](https://img.shields.io/packagist/v/illuminated/console-logger)
1212
![Packagist Stars](https://img.shields.io/packagist/stars/illuminated/console-logger)
@@ -17,6 +17,8 @@ Logging and Notifications for Laravel Console Commands.
1717

1818
| Laravel | Console Logger |
1919
|---------|---------------------------------------------------------------------------|
20+
| 11.x | _[Support](https://buymeacoffee.com/dmitry.ivanov)_|
21+
| 10.x | [10.x](https://github.com/dmitry-ivanov/laravel-console-logger/tree/10.x) |
2022
| 9.x | [9.x](https://github.com/dmitry-ivanov/laravel-console-logger/tree/9.x) |
2123
| 8.x | [8.x](https://github.com/dmitry-ivanov/laravel-console-logger/tree/8.x) |
2224
| 7.x | [7.x](https://github.com/dmitry-ivanov/laravel-console-logger/tree/7.x) |
@@ -477,5 +479,4 @@ class ExampleCommand extends Command
477479

478480
Laravel Console Logger is open-sourced software licensed under the [MIT license](LICENSE.md).
479481

480-
[<img src="https://user-images.githubusercontent.com/1286821/43086829-ff7c006e-8ea6-11e8-8b03-ecf97ca95b2e.png" alt="Support on Patreon" width="125" />](https://patreon.com/dmitryivanov)&nbsp;
481482
[<img src="https://user-images.githubusercontent.com/1286821/181085373-12eee197-187a-4438-90fe-571ac6d68900.png" alt="Buy me a coffee" width="200" />](https://buymeacoffee.com/dmitry.ivanov)&nbsp;

Diff for: composer.json

+11-12
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,21 @@
1212
"email": "[email protected]"
1313
}],
1414
"require": {
15-
"php": "^8.0.2",
16-
"illuminate/console": "^9.0",
17-
"illuminate/support": "^9.0",
18-
"illuminated/helper-functions": "^9.1",
19-
"monolog/monolog": "^2.6",
15+
"php": "^8.1",
16+
"illuminate/console": "^10.0",
17+
"illuminate/support": "^10.0",
18+
"illuminated/helper-functions": "^10.0",
19+
"monolog/monolog": "^3.0",
2020
"psr/http-message": "^1.0",
2121
"psr/log": "^1.0|^2.0|^3.0",
22-
"ramsey/collection": "^1.2",
23-
"symfony/finder": "^6.0"
22+
"symfony/finder": "^6.2"
2423
},
2524
"require-dev": {
26-
"phpunit/phpunit": "^9.5.10",
27-
"mockery/mockery": "^1.4.4",
28-
"guzzlehttp/guzzle": "^7.2",
29-
"orchestra/testbench": "^7.0",
30-
"illuminated/testing-tools": "^9.0"
25+
"phpunit/phpunit": "^10.5",
26+
"mockery/mockery": "^1.5.1",
27+
"guzzlehttp/guzzle": "^7.5",
28+
"orchestra/testbench": "^8.0",
29+
"illuminated/testing-tools": "^10.0"
3130
},
3231
"autoload": {
3332
"files": [

Diff for: phpunit.xml.dist

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,25 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
33
backupGlobals="false"
4-
backupStaticAttributes="false"
4+
backupStaticProperties="false"
55
beStrictAboutTestsThatDoNotTestAnything="false"
66
beStrictAboutOutputDuringTests="true"
77
bootstrap="vendor/autoload.php"
8+
cacheDirectory=".phpunit.cache"
89
colors="true"
9-
convertErrorsToExceptions="true"
10-
convertNoticesToExceptions="true"
11-
convertWarningsToExceptions="true"
1210
processIsolation="false"
1311
stopOnError="false"
1412
stopOnFailure="false"
15-
verbose="true"
1613
>
1714
<testsuites>
1815
<testsuite name="Laravel Console Logger Test Suite">
1916
<directory suffix="Test.php">./tests</directory>
2017
</testsuite>
2118
</testsuites>
2219

23-
<coverage processUncoveredFiles="true">
20+
<source>
2421
<include>
2522
<directory suffix=".php">./src</directory>
2623
</include>
27-
</coverage>
24+
</source>
2825
</phpunit>

Diff for: src/Loggable/FileChannel/MonologFormatter.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Illuminated\Console\Loggable\FileChannel;
44

55
use Monolog\Formatter\LineFormatter;
6+
use Monolog\LogRecord;
67

78
class MonologFormatter extends LineFormatter
89
{
@@ -17,9 +18,9 @@ public function __construct()
1718
/**
1819
* Formats a log record.
1920
*/
20-
public function format(array $record): string
21+
public function format(LogRecord $record): string
2122
{
22-
if ($record['message'] == '%separator%') {
23+
if ($record->message == '%separator%') {
2324
return str_repeat("\n", 11);
2425
}
2526

Diff for: src/Loggable/Notifications/DatabaseChannel/DatabaseChannel.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Illuminated\Console\Loggable\Notifications\DatabaseChannel;
44

5-
use Monolog\Logger;
5+
use Monolog\Level;
66

77
trait DatabaseChannel
88
{
@@ -35,9 +35,9 @@ protected function getDatabaseChannelHandler(): MonologDatabaseHandler|false
3535
/**
3636
* Get the database notifications level.
3737
*/
38-
protected function getDatabaseNotificationsLevel(): int
38+
protected function getDatabaseNotificationsLevel(): Level
3939
{
40-
return Logger::NOTICE;
40+
return Level::Notice;
4141
}
4242

4343
/**

Diff for: src/Loggable/Notifications/DatabaseChannel/MonologDatabaseHandler.php

+9-8
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
use Illuminate\Support\Facades\DB;
88
use Illuminate\Support\Facades\Schema;
99
use Monolog\Handler\AbstractProcessingHandler;
10-
use Monolog\Logger;
10+
use Monolog\Level;
11+
use Monolog\LogRecord;
1112

1213
class MonologDatabaseHandler extends AbstractProcessingHandler
1314
{
@@ -24,7 +25,7 @@ class MonologDatabaseHandler extends AbstractProcessingHandler
2425
/**
2526
* Create a new instance of the handler.
2627
*/
27-
public function __construct(string $table = 'iclogger_notifications', callable $callback = null, int $level = Logger::DEBUG, bool $bubble = true)
28+
public function __construct(string $table = 'iclogger_notifications', callable $callback = null, int|string|Level $level = Level::Debug, bool $bubble = true)
2829
{
2930
$this->table = $table;
3031
$this->callback = $callback;
@@ -57,21 +58,21 @@ protected function guaranteeTableExists(): void
5758
/**
5859
* Write the record down to the database.
5960
*/
60-
protected function write(array $record): void
61+
protected function write(LogRecord $record): void
6162
{
6263
if (!empty($this->callback)) {
63-
call_user_func($this->callback, $record);
64+
call_user_func($this->callback, $record->toArray());
6465
return;
6566
}
6667

6768
// We're using Carbon here, because not all database drivers have `now()` function (i.e., `sqlite`)
6869
$now = Carbon::now();
6970

7071
DB::table($this->table)->insert([
71-
'level' => $record['level'],
72-
'level_name' => $record['level_name'],
73-
'message' => $record['message'],
74-
'context' => get_dump($record['context']),
72+
'level' => $record->level->value,
73+
'level_name' => $record->level->getName(),
74+
'message' => $record->message,
75+
'context' => get_dump($record->context),
7576
'created_at' => $now,
7677
'updated_at' => $now,
7778
]);

Diff for: src/Loggable/Notifications/EmailChannel/EmailChannel.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Illuminate\Support\Str;
66
use Monolog\Handler\DeduplicationHandler;
77
use Monolog\Handler\SymfonyMailerHandler;
8-
use Monolog\Logger;
8+
use Monolog\Level;
99
use Symfony\Component\Mime\Email;
1010

1111
trait EmailChannel
@@ -54,9 +54,9 @@ protected function getEmailChannelHandler(): SymfonyMailerHandler|DeduplicationH
5454
/**
5555
* Get the email notifications level.
5656
*/
57-
protected function getEmailNotificationsLevel(): int
57+
protected function getEmailNotificationsLevel(): Level
5858
{
59-
return Logger::NOTICE;
59+
return Level::Notice;
6060
}
6161

6262
/**

Diff for: src/Loggable/Notifications/EmailChannel/MonologHtmlFormatter.php

+24-13
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
use Illuminate\Support\Str;
66
use Monolog\Formatter\HtmlFormatter;
7+
use Monolog\Level;
8+
use Monolog\LogRecord;
79

810
class MonologHtmlFormatter extends HtmlFormatter
911
{
@@ -18,7 +20,7 @@ public function __construct()
1820
/**
1921
* Formats a log record.
2022
*/
21-
public function format(array $record): string
23+
public function format(LogRecord $record): string
2224
{
2325
$output = '<!DOCTYPE html>';
2426
$output .= '<html lang="en">';
@@ -42,18 +44,27 @@ public function format(array $record): string
4244
/**
4345
* Get color for the given level.
4446
*/
45-
public function getLevelColor(int $level): string
47+
public function getLevelColor(Level $level): string
4648
{
47-
return $this->logLevels[$level];
49+
return match ($level) {
50+
Level::Debug => '#CCCCCC',
51+
Level::Info => '#28A745',
52+
Level::Notice => '#17A2B8',
53+
Level::Warning => '#FFC107',
54+
Level::Error => '#FD7E14',
55+
Level::Critical => '#DC3545',
56+
Level::Alert => '#821722',
57+
Level::Emergency => '#000000',
58+
};
4859
}
4960

5061
/**
5162
* Compose style for the given record.
5263
*/
53-
protected function composeStyle(array $record): string
64+
protected function composeStyle(LogRecord $record): string
5465
{
55-
$level = $record['level'];
56-
$levelName = $record['level_name'];
66+
$level = $record->level;
67+
$levelName = $record->level->getName();
5768
$levelColor = $this->getLevelColor($level);
5869

5970
return "<link href='https://fonts.googleapis.com/css?family=Lato' rel='stylesheet' type='text/css'>
@@ -91,9 +102,9 @@ protected function composeStyle(array $record): string
91102
/**
92103
* Compose title for the given record.
93104
*/
94-
protected function composeTitle(array $record): string
105+
protected function composeTitle(LogRecord $record): string
95106
{
96-
$levelName = e($record['level_name']);
107+
$levelName = e($record->level->getName());
97108
$title = "<h2 class='title {$levelName}'>{$levelName}</h2>";
98109

99110
if (app()->isProduction()) {
@@ -111,16 +122,16 @@ protected function composeTitle(array $record): string
111122
/**
112123
* Compose details for the given record.
113124
*/
114-
protected function composeDetails(array $record): string
125+
protected function composeDetails(LogRecord $record): string
115126
{
116127
$details = '<table cellspacing="1" width="100%">';
117128

118-
$details .= $this->composeDetailsRow('Message', (string) $record['message']);
119-
if (!empty($record['context'])) {
120-
$context = $this->convertToString($record['context']);
129+
$details .= $this->composeDetailsRow('Message', $record->message);
130+
if (!empty($record->context)) {
131+
$context = $this->convertToString($record->context);
121132
$details .= $this->composeDetailsRow('Context', $context);
122133
}
123-
$details .= $this->composeDetailsRow('Time', $record['datetime']->format($this->dateFormat));
134+
$details .= $this->composeDetailsRow('Time', $record->datetime->format($this->dateFormat));
124135

125136
$details .= '</table>';
126137

0 commit comments

Comments
 (0)