-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ログに process_type を出力するための独自 Processor を定義
- Loading branch information
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace App\Logging; | ||
|
||
/** | ||
* Class ProcessTypeProcessor | ||
* @package App\Logging | ||
*/ | ||
class ProcessTypeProcessor | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $processType; | ||
|
||
/** | ||
* ProcessTypeProcessor constructor. | ||
*/ | ||
public function __construct() | ||
{ | ||
if (app()->runningInConsole()) { | ||
$this->processType = 'console'; | ||
return; | ||
} | ||
|
||
if (app()->runningUnitTests()) { | ||
$this->processType = 'test'; | ||
return; | ||
} | ||
|
||
// console, test のどちらでもなければ消去法で web | ||
$this->processType = 'web'; | ||
} | ||
|
||
/** | ||
* @param array $record | ||
* @return array | ||
*/ | ||
public function __invoke(array $record): array | ||
{ | ||
$record['extra']['process_type'] = $this->processType; | ||
|
||
return $record; | ||
} | ||
} |