Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prints server logs to "stderr" #326

Merged
merged 2 commits into from
Jun 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions src/Commands/Concerns/InteractsWithIO.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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',
];

/**
Expand All @@ -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::startsWith($string, $this->ignoreMessages)) {
$this->output instanceof OutputStyle
? fwrite(STDERR, $string."\n")
: $this->output->writeln($string);
nunomaduro marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down Expand Up @@ -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([
'',
" <bg=$background;fg=$foreground;options=bold> $level </> $string",
Expand Down
6 changes: 5 additions & 1 deletion src/Commands/StartRoadRunnerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
nunomaduro marked this conversation as resolved.
Show resolved Hide resolved
'-o', app()->environment('local') ? 'logs.level=debug' : 'logs.level=warning',
'-o', 'logs.output=stdout',
'-o', 'logs.encoding=json',
Expand Down Expand Up @@ -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']);

Expand Down
15 changes: 1 addition & 14 deletions src/Commands/StartSwooleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(' <fg=red;options=bold>↑</> %s %s',
$count,
$count > 1
? 'similar errors were reported.'
: 'similar error was reported.'
));
}
: $this->raw($output);
});
}

Expand Down