laravel / octane

Supercharge your Laravel application's performance.
https://laravel.com/docs/octane
MIT License
3.74k stars 291 forks source link

Flag to enable JSON log output for FrankenPHP #815

Closed binaryfire closed 7 months ago

binaryfire commented 7 months ago

Hi @dunglas

I'm experiencing the same issue as this user: https://www.reddit.com/r/laravel/comments/194tyfo/comment/khiuwy1/. We need the log output in production to be in JSON format to send to our log aggregator.

Would it be possible to add a flag for that to the start command?

Cheers

binaryfire commented 7 months ago

Hey @driesvints, just saw the needs more info tag. If you check out this code you'll see that standard json output is being converted into "human friendly" format by Octane.

Log aggregation services like Logstash, Datadog, Grafana Loki etc. all require logs to be in JSON format.

I'd be happy to make a PR for flag for this, but getting PHP to just re-write Caddy's JSON output seems like unnecessary performance overhead. I'm wondering if a flag to disable logging is a better option, so long as there's an easy way to access Caddy's logs directly. Hoping @dunglas can help.

dunglas commented 7 months ago

Hi @binaryfire,

If you explicitly set the --log-level parameter, you'll get JSON logs: https://github.com/laravel/octane/blob/83c2afb9a7a8dd410e76454fec8e4b823724a4b8/src/Commands/StartFrankenPhpCommand.php#L266C28-L268

binaryfire commented 7 months ago

@dunglas Ah didn't realise that forced JSON. Thanks.