Skip to content

Commit abdce3c

Browse files
committed
Add error log output
1 parent bc0cea4 commit abdce3c

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

config/soar.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
// Guanguans\LaravelSoar\Outputs\ClockworkOutput::class,
3939
// Guanguans\LaravelSoar\Outputs\ConsoleOutput::class,
4040
// Guanguans\LaravelSoar\Outputs\DumpOutput::class => ['exit' => false],
41+
// Guanguans\LaravelSoar\Outputs\ErrorLogOutput::class => ['messageType' => 0, 'destination' => '', 'extraHeaders' => ''],
4142
// Guanguans\LaravelSoar\Outputs\RayOutput::class => ['label' => 'Soar Scores'],
4243
// Guanguans\LaravelSoar\Outputs\SyslogOutput::class,
4344
Guanguans\LaravelSoar\Outputs\JsonOutput::class => ['key' => 'soar_scores'],

src/Outputs/ErrorLogOutput.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of the guanguans/laravel-soar.
7+
*
8+
* (c) guanguans <ityaozm@gmail.com>
9+
*
10+
* This source file is subject to the MIT license that is bundled.
11+
*/
12+
13+
namespace Guanguans\LaravelSoar\Outputs;
14+
15+
use Illuminate\Support\Collection;
16+
17+
class ErrorLogOutput extends Output
18+
{
19+
protected int $messageType;
20+
protected string $destination;
21+
protected string $extraHeaders;
22+
23+
public function __construct(int $messageType = 0, string $destination = '', string $extraHeaders = '')
24+
{
25+
$this->messageType = $messageType;
26+
$this->destination = $destination;
27+
$this->extraHeaders = $extraHeaders;
28+
}
29+
30+
/**
31+
* {@inheritDoc}
32+
*
33+
* @throws \JsonException
34+
*
35+
* @noinspection ForgottenDebugOutputInspection
36+
* @noinspection DebugFunctionUsageInspection
37+
*/
38+
public function output(Collection $scores, $dispatcher): void
39+
{
40+
$scores->each(fn (array $score) => error_log(
41+
$score['Summary'].PHP_EOL.to_pretty_json($score),
42+
$this->messageType,
43+
$this->destination,
44+
$this->extraHeaders,
45+
));
46+
}
47+
}

tests/TestCase.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@
1919
use Guanguans\LaravelSoar\Outputs\ConsoleOutput;
2020
use Guanguans\LaravelSoar\Outputs\DebugBarOutput;
2121
use Guanguans\LaravelSoar\Outputs\DumpOutput;
22+
use Guanguans\LaravelSoar\Outputs\ErrorLogOutput;
2223
use Guanguans\LaravelSoar\Outputs\JsonOutput;
2324
use Guanguans\LaravelSoar\Outputs\LogOutput;
2425
use Guanguans\LaravelSoar\Outputs\NullOutput;
2526
use Guanguans\LaravelSoar\Outputs\RayOutput;
2627
use Guanguans\LaravelSoar\Outputs\SoarBarOutput;
28+
use Guanguans\LaravelSoar\Outputs\SyslogOutput;
2729
use Guanguans\LaravelSoar\SoarServiceProvider;
2830
use Illuminate\Database\Schema\Blueprint;
2931
use Illuminate\Support\Facades\Artisan;
@@ -70,7 +72,8 @@ protected function defineEnvironment($app): void
7072
ConsoleOutput::class,
7173
// \Guanguans\LaravelSoar\Outputs\DebugBarOutput::class,
7274
// \Guanguans\LaravelSoar\Outputs\DumpOutput::class => ['exit' => false],
73-
\Guanguans\LaravelSoar\Outputs\SyslogOutput::class,
75+
SyslogOutput::class,
76+
ErrorLogOutput::class,
7477
JsonOutput::class,
7578
LogOutput::class => ['channel' => 'daily'],
7679
NullOutput::class,

0 commit comments

Comments
 (0)