Skip to content

Commit 6c1126e

Browse files
authored
Release v2.0.0
2 parents 366430a + c703120 commit 6c1126e

8 files changed

Lines changed: 57 additions & 75 deletions

File tree

.github/workflows/test-package.yml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,8 @@ jobs:
88
strategy:
99
fail-fast: false
1010
matrix:
11-
php-version: ['5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1']
12-
psr-log-version: ['^1.0']
13-
14-
include:
15-
- php-version: '8.0'
16-
psr-log-version: '^2.0'
17-
- php-version: '8.1'
18-
psr-log-version: '^2.0'
11+
php-version: ['8.0', '8.1']
12+
psr-log-version: ['^2.0', '^3.0']
1913

2014
steps:
2115
- uses: actions/checkout@v2

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
11
Changelog
22
=========
33

4+
## 2.0.0 (2022-01-12)
5+
6+
### Enhancements
7+
8+
* Support PSR Log v3
9+
[#51](https://github.com/bugsnag/bugsnag-psr-logger/pull/51)
10+
11+
### Breaking changes
12+
13+
* PSR Log v1 is no longer supported. Use `bugsnag/bugsnag-psr-logger:^1.0` for PSR Log v1 support
14+
15+
The following changes are breaking for users extending any of the classes provided by this package, but should not otherwise be noticeable:
16+
17+
* Removed `Bugsnag\PsrLogger\AbstractLogger` in favour of using `Psr\Log\AbstractLogger` directly
18+
* Added parameter and return types throughout `Bugsnag\PsrLogger\BugsnagLogger` and `Bugsnag\PsrLogger\MultiLogger`
19+
* Removed protected `Bugsnag\PsrLogger\BugsnagLogger::limit` method
20+
421
## 1.4.5 (2021-12-13)
522

623
### Deprecations

composer.json

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
"homepage": "https://bugsnag.com"
1212
}],
1313
"require": {
14-
"php": ">=5.5",
14+
"php": ">=8.0",
1515
"bugsnag/bugsnag": "^3.10",
16-
"psr/log": "^1.0|^2.0"
16+
"psr/log": "^2.0|^3.0"
1717
},
1818
"require-dev": {
1919
"graham-campbell/testbench-core": "^1.1",
20-
"mockery/mockery": "^0.9.4|^1.3.1",
21-
"phpunit/phpunit": "^4.8.36|^7.5.15|^9.4.3"
20+
"mockery/mockery": "^1.3.1",
21+
"phpunit/phpunit": "^9.4.3"
2222
},
2323
"autoload": {
2424
"psr-4" : {
@@ -29,12 +29,5 @@
2929
"psr-4" : {
3030
"Bugsnag\\PsrLogger\\Tests\\" : "tests/"
3131
}
32-
},
33-
"extra": {
34-
"branch-alias": {
35-
"dev-master": "1.5-dev"
36-
}
37-
},
38-
"minimum-stability": "dev",
39-
"prefer-stable": true
32+
}
4033
}

src/AbstractLogger.php

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/BugsnagLogger.php

Lines changed: 20 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use Bugsnag\Client;
66
use Bugsnag\Report;
7-
use Exception;
7+
use Psr\Log\AbstractLogger;
88
use Psr\Log\LogLevel;
99
use Throwable;
1010

@@ -15,7 +15,7 @@ class BugsnagLogger extends AbstractLogger
1515
*
1616
* @var \Bugsnag\Client
1717
*/
18-
protected $client;
18+
protected Client $client;
1919

2020
/**
2121
* The minimum level required to notify bugsnag.
@@ -24,7 +24,7 @@ class BugsnagLogger extends AbstractLogger
2424
*
2525
* @var string
2626
*/
27-
protected $notifyLevel = LogLevel::NOTICE;
27+
protected string $notifyLevel = LogLevel::NOTICE;
2828

2929
/**
3030
* Create a new bugsnag logger instance.
@@ -45,7 +45,7 @@ public function __construct(Client $client)
4545
*
4646
* @return void
4747
*/
48-
public function setNotifyLevel($notifyLevel)
48+
public function setNotifyLevel(string $notifyLevel): void
4949
{
5050
if (!in_array($notifyLevel, $this->getLogLevelOrder())) {
5151
syslog(LOG_WARNING, 'Bugsnag Warning: Invalid notify level supplied to Bugsnag Logger');
@@ -57,13 +57,13 @@ public function setNotifyLevel($notifyLevel)
5757
/**
5858
* Log a message to the logs.
5959
*
60-
* @param string $level
61-
* @param mixed $message
62-
* @param array $context
60+
* @param mixed $level
61+
* @param string|\Stringable $message
62+
* @param mixed[] $context
6363
*
6464
* @return void
6565
*/
66-
public function log($level, $message, array $context = [])
66+
public function log(mixed $level, string|\Stringable $message, array $context = []): void
6767
{
6868
$title = 'Log '.$level;
6969
if (isset($context['title'])) {
@@ -72,10 +72,10 @@ public function log($level, $message, array $context = [])
7272
}
7373

7474
$exception = null;
75-
if (isset($context['exception']) && ($context['exception'] instanceof Exception || $context['exception'] instanceof Throwable)) {
75+
if (isset($context['exception']) && $context['exception'] instanceof Throwable) {
7676
$exception = $context['exception'];
7777
unset($context['exception']);
78-
} elseif ($message instanceof Exception || $message instanceof Throwable) {
78+
} elseif ($message instanceof Throwable) {
7979
$exception = $message;
8080
}
8181

@@ -118,12 +118,12 @@ public function log($level, $message, array $context = [])
118118
/**
119119
* Checks whether the selected level is above another level.
120120
*
121-
* @param string $level
121+
* @param mixed $level
122122
* @param string $base
123123
*
124124
* @return bool
125125
*/
126-
protected function aboveLevel($level, $base)
126+
protected function aboveLevel(mixed $level, string $base): bool
127127
{
128128
$levelOrder = $this->getLogLevelOrder();
129129
$baseIndex = array_search($base, $levelOrder);
@@ -137,7 +137,7 @@ protected function aboveLevel($level, $base)
137137
*
138138
* @return string[]
139139
*/
140-
protected function getLogLevelOrder()
140+
protected function getLogLevelOrder(): array
141141
{
142142
return [
143143
LogLevel::DEBUG,
@@ -154,11 +154,11 @@ protected function getLogLevelOrder()
154154
/**
155155
* Get the severity for the logger.
156156
*
157-
* @param string $level
157+
* @param mixed $level
158158
*
159159
* @return string
160160
*/
161-
protected function getSeverity($level)
161+
protected function getSeverity(mixed $level): string
162162
{
163163
if ($this->aboveLevel($level, 'error')) {
164164
return 'error';
@@ -172,32 +172,16 @@ protected function getSeverity($level)
172172
/**
173173
* Format the parameters for the logger.
174174
*
175-
* @param mixed $message
175+
* @param string|\Stringable $message
176176
*
177177
* @return string
178178
*/
179-
protected function formatMessage($message)
179+
protected function formatMessage(string|\Stringable $message): string
180180
{
181-
if (is_array($message)) {
182-
return var_export($message, true);
181+
if (is_string($message)) {
182+
return $message;
183183
}
184184

185-
return $message;
186-
}
187-
188-
/**
189-
* Ensure the given string is less than 100 characters.
190-
*
191-
* @param string $str
192-
*
193-
* @return string
194-
*/
195-
protected function limit($str)
196-
{
197-
if (strlen($str) <= 100) {
198-
return $str;
199-
}
200-
201-
return rtrim(substr($str, 0, 97)).'...';
185+
return (string) $message;
202186
}
203187
}

src/MultiLogger.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22

33
namespace Bugsnag\PsrLogger;
44

5+
use Psr\Log\AbstractLogger;
6+
57
class MultiLogger extends AbstractLogger
68
{
79
/**
810
* The registered loggers.
911
*
1012
* @var \Psr\Log\LoggerInterface[]
1113
*/
12-
protected $loggers;
14+
protected array $loggers;
1315

1416
/**
1517
* Create a new multi logger instance.
@@ -26,13 +28,13 @@ public function __construct(array $loggers)
2628
/**
2729
* Log a message to the logs.
2830
*
29-
* @param string $level
30-
* @param mixed $message
31-
* @param array $context
31+
* @param mixed $level
32+
* @param string|\Stringable $message
33+
* @param mixed[] $context
3234
*
3335
* @return void
3436
*/
35-
public function log($level, $message, array $context = [])
37+
public function log(mixed $level, string|\Stringable $message, array $context = []): void
3638
{
3739
foreach ($this->loggers as $logger) {
3840
$logger->log($level, $message, $context);

tests/BugsnagLoggerTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use GrahamCampbell\TestBenchCore\MockeryTrait;
99
use Mockery;
1010
use PHPUnit\Framework\TestCase;
11+
use Psr\Log\LoggerInterface;
1112

1213
class ReportStub
1314
{
@@ -276,12 +277,12 @@ public function testInvalidLogLevelCallsSyslog()
276277
$this->assertEquals($sysmes, 'Bugsnag Warning: Invalid notify level supplied to Bugsnag Logger');
277278
}
278279

279-
public function testIsAbstractLogger()
280+
public function testIsLoggerInterface()
280281
{
281282
$client = Mockery::mock(Client::class);
282283
$logger = new BugsnagLogger($client);
283284

284-
$this->assertInstanceOf(AbstractLogger::class, $logger);
285+
$this->assertInstanceOf(LoggerInterface::class, $logger);
285286
}
286287

287288
/**

tests/MultiLoggerTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use GrahamCampbell\TestBenchCore\MockeryTrait;
66
use Mockery;
77
use PHPUnit\Framework\TestCase;
8+
use Psr\Log\LoggerInterface;
89

910
class MultiLoggerTest extends TestCase
1011
{
@@ -34,11 +35,11 @@ public function testWarning()
3435
$multi->warning('hi!', ['foo' => 'baz']);
3536
}
3637

37-
public function testIsAbstractLogger()
38+
public function testIsLoggerInterface()
3839
{
3940
$one = Mockery::mock(LoggerInterface::class);
4041
$logger = new MultiLogger([$one]);
4142

42-
$this->assertInstanceOf(AbstractLogger::class, $logger);
43+
$this->assertInstanceOf(LoggerInterface::class, $logger);
4344
}
4445
}

0 commit comments

Comments
 (0)