Skip to content

Commit

Permalink
ログに process_type を出力するための独自 Processor を定義
Browse files Browse the repository at this point in the history
  • Loading branch information
okashoi committed Mar 17, 2019
1 parent c4be2a4 commit c293541
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/app/Logging/ProcessTypeProcessor.php
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;
}
}

0 comments on commit c293541

Please sign in to comment.