Skip to content

Commit

Permalink
Interfaces changes for monolog 3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
judgej committed Sep 21, 2023
1 parent 9fcc602 commit d37f9a5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
}
},
"require": {
"php": "^7.3|^7.4|^8.0",
"illuminate/support": "~5.6|^6.0|^7.0|^8.0|^9.0|^10.0"
"php": "^8.1",
"illuminate/support": "^10.0",
"monolog/monolog": "^3.0"
},
"extra": {
"laravel": {
Expand Down
9 changes: 5 additions & 4 deletions src/Processor/AppNameProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
* Add the local user ID to extra if a user is logged in.
*/

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

class AppNameProcessor implements ProcessorInterface
{
Expand All @@ -20,16 +21,16 @@ public function __construct()
$this->subsystem = config('app.subsystem');
}

public function __invoke(array $record)
public function __invoke(LogRecord $record)
{
// Add system and subsystem names.

if ($this->application) {
$record['extra']['application'] = $this->application;
$record->extra['application'] = $this->application;
}

if ($this->subsystem) {
$record['extra']['subsystem'] = $this->subsystem;
$record->extra['subsystem'] = $this->subsystem;
}

return $record;
Expand Down
9 changes: 5 additions & 4 deletions src/Processor/AuthUserProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@
* Add the local user ID to extra if a user is logged in.
*/

use Monolog\Processor\ProcessorInterface;
use Throwable;
use Monolog\LogRecord;
use Monolog\ResettableInterface;
use Illuminate\Support\Facades\Auth;
use Throwable;
use Monolog\Processor\ProcessorInterface;

class AuthUserProcessor implements ProcessorInterface, ResettableInterface
{
protected $userId;

public function __invoke(array $record)
public function __invoke(LogRecord $record)
{
if ($userId = $this->getUserId()) {
$record['extra']['local_user_id'] = $userId;
$record->extra['local_user_id'] = $userId;
}

return $record;
Expand Down
7 changes: 4 additions & 3 deletions src/Processor/JobNameProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@
* Add the currently running job name to the log messages.
*/

use Monolog\Processor\ProcessorInterface;
use Monolog\LogRecord;
use Monolog\ResettableInterface;
use Monolog\Processor\ProcessorInterface;
use Consilience\Laravel\ExtendedLogging\LoggingService;

class JobNameProcessor implements ProcessorInterface
{
public function __invoke(array $record)
public function __invoke(LogRecord $record)
{
$jobName = app(LoggingService::class)->getJobName();

if ($jobName) {
$record['extra']['job_name'] = $jobName;
$record->extra['job_name'] = $jobName;
}

return $record;
Expand Down

0 comments on commit d37f9a5

Please sign in to comment.