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

Add “raw” type in handleStream method for custom json in stdout #742

Merged
merged 1 commit into from
Aug 29, 2023

Conversation

mphamid
Copy link
Contributor

@mphamid mphamid commented Aug 28, 2023

To implement the filebeat logs in stdout during the execution of the project with octane, all outputs are displayed with the info method in the output, which causes a change in the output of stdout and makes it difficult to implement filebeat using stdout.
My suggestion is to create a new type in the handleStream method and use it whenever we need to send a specific json in the output.

@taylorotwell
Copy link
Member

How do you use this?

@mphamid
Copy link
Contributor Author

mphamid commented Aug 29, 2023

I created a new log channel

'filebeat_stdout' => [
            'driver' => 'monolog',
            'handler' => StreamHandler::class,
            'formatter' => FilebeatFormatter::class,
            'level' => env('LOG_LEVEL', 'debug'),
            'with' => [
                'stream' => 'php://stdout',
            ],
        ],

And I created the output in FilebeatFormatter::class file like this

use Monolog\Formatter\JsonFormatter;
use Monolog\LogRecord;

class FilebeatFormatter extends JsonFormatter
{
    /**
     * @inheritDoc
     */
    public function format(LogRecord $record): string
    {
        $normalized = json_decode(parent::format($record),true);
        $normalized['application'] = config('app.name');
        $normalized['type'] = 'raw';
        return $this->toJson($normalized, true) . ($this->appendNewline ? "\n" : '');
    }
}

But now my output is showing an info in stdout

@taylorotwell taylorotwell merged commit 112bddc into laravel:2.x Aug 29, 2023
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants