From c4f9e431e394e15bf04bb26f532bbd992328e495 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Tue, 15 Jun 2021 14:03:54 +0100 Subject: [PATCH 1/2] Prints server logs to "stderr" --- src/Commands/Concerns/InteractsWithIO.php | 25 +++++++++++++++++++---- src/Commands/StartRoadRunnerCommand.php | 6 +++++- src/Commands/StartSwooleCommand.php | 15 +------------- 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/Commands/Concerns/InteractsWithIO.php b/src/Commands/Concerns/InteractsWithIO.php index d8c0fb0ed..dda896ef7 100644 --- a/src/Commands/Concerns/InteractsWithIO.php +++ b/src/Commands/Concerns/InteractsWithIO.php @@ -2,6 +2,7 @@ namespace Laravel\Octane\Commands\Concerns; +use Illuminate\Console\OutputStyle; use Illuminate\Support\Str; use Laravel\Octane\Exceptions\DdException; use Laravel\Octane\Exceptions\ServerShutdownException; @@ -19,9 +20,12 @@ trait InteractsWithIO * * @var array */ - protected $ignoreErrors = [ + protected $ignoreMessages = [ + 'scan command', 'stop signal received, grace timeout is: ', 'exit forced', + 'worker constructed', + 'worker destructed', ]; /** @@ -45,8 +49,21 @@ public function info($string, $verbosity = null) */ public function error($string, $verbosity = null) { - if (! Str::contains($string, $this->ignoreErrors)) { - $this->label($string, $verbosity, 'ERROR', 'red', 'white'); + $this->label($string, $verbosity, 'ERROR', 'red', 'white'); + } + + /** + * Write a string as raw output. + * + * @param string $string + * @return void + */ + public function raw($string) + { + if (! Str::contains($string, $this->ignoreMessages)) { + $this->output instanceof OutputStyle + ? fwrite(STDERR, $string."\n") + : $this->output->writeln($string); } } @@ -74,7 +91,7 @@ public function warn($string, $verbosity = null) */ public function label($string, $verbosity, $level, $background, $foreground) { - if (! empty($string)) { + if (! empty($string) && ! Str::startsWith($string, $this->ignoreMessages)) { $this->output->writeln([ '', " $level $string", diff --git a/src/Commands/StartRoadRunnerCommand.php b/src/Commands/StartRoadRunnerCommand.php index b8b7e4dca..24c483d88 100644 --- a/src/Commands/StartRoadRunnerCommand.php +++ b/src/Commands/StartRoadRunnerCommand.php @@ -84,7 +84,7 @@ public function handle(ServerProcessInspector $inspector, ServerStateFile $serve '-o', 'http.pool.supervisor.exec_ttl='.$this->maxExecutionTime(), '-o', 'http.static.dir=public', '-o', 'http.middleware=static', - '-o', app()->environment('local') ? 'logs.mode=production' : 'logs.mode=none', + '-o', 'logs.mode=production', '-o', app()->environment('local') ? 'logs.level=debug' : 'logs.level=warning', '-o', 'logs.output=stdout', '-o', 'logs.encoding=json', @@ -172,6 +172,10 @@ protected function writeServerOutput($server) return $this->handleStream($stream); } + if ($debug['logger'] == 'server') { + return $this->raw($debug['msg']); + } + if ($debug['level'] == 'debug' && isset($debug['remote'])) { [$statusCode, $method, $url] = explode(' ', $debug['msg']); diff --git a/src/Commands/StartSwooleCommand.php b/src/Commands/StartSwooleCommand.php index 8a3be8953..a7cf5e7a4 100644 --- a/src/Commands/StartSwooleCommand.php +++ b/src/Commands/StartSwooleCommand.php @@ -179,20 +179,7 @@ protected function writeServerOutput($server) ->each(function ($group) { is_array($stream = json_decode($output = $group->first(), true)) && isset($stream['type']) ? $this->handleStream($stream) - : $this->error($output); - - if (($count = $group->count()) > 1) { - $this->newLine(); - - $count--; - - $this->line(sprintf(' ↑ %s %s', - $count, - $count > 1 - ? 'similar errors were reported.' - : 'similar error was reported.' - )); - } + : $this->raw($output); }); } From bb5b628a28f10f754ec318d3857becd9c9f3bfd9 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Tue, 15 Jun 2021 14:25:38 +0100 Subject: [PATCH 2/2] Ignores messages startingWith --- src/Commands/Concerns/InteractsWithIO.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Commands/Concerns/InteractsWithIO.php b/src/Commands/Concerns/InteractsWithIO.php index dda896ef7..1dcc7ae0f 100644 --- a/src/Commands/Concerns/InteractsWithIO.php +++ b/src/Commands/Concerns/InteractsWithIO.php @@ -60,7 +60,7 @@ public function error($string, $verbosity = null) */ public function raw($string) { - if (! Str::contains($string, $this->ignoreMessages)) { + if (! Str::startsWith($string, $this->ignoreMessages)) { $this->output instanceof OutputStyle ? fwrite(STDERR, $string."\n") : $this->output->writeln($string);