Sending Laravel logs to Railway's logger
Hey pals, trying to sort out how to actually get Laravel to send logs to Railway's console. I'm using the vanilla Nixpacks PHP/Laravel builder: https://github.com/railwayapp/nixpacks/blob/main/src/providers/php/mod.rs
And I've set my logger.php config to use a stdout driver, which is a copy/paste of the stderr driver except with stdout swapped in:
[
'stdout' => [
'driver' => 'monolog',
'handler' => StreamHandler::class,
'formatter' => env('LOG_STDERR_FORMATTER'),
'with' => [
'stream' => 'php://stdout',
],
'ignore_exceptions' => false,
],
]
I'm not seeing anything come through - only nginx logs. Any thoughts on how I could route these to the right place? Off-the-cuff thoughts:
- Does php-fpm swallow these logs? Like, do they go into the ether?
- Or is it possible to write to /dev/stdout from multiple processes like I'm trying to do?
☮️ 🙏
8 Replies
Project ID:
7605ac5c-d0a3-4cfb-a00a-49878fd419a8
7605ac5c-d0a3-4cfb-a00a-49878fd419a8
Does php-fpm swallow these logs? Like, do they go into the ether?good question, i have no clue
Or is it possible to write to /dev/stdout from multiple processes like I'm trying to do?it should be, thats what nginx does as far as i know
hmmm yeah i'm gonna try on my local machine to see how writing to stdout behaves 🤔
hmm chatgpt confirms my suspicions about stdout:
Correct, you cannot directly read from /dev/stdout of another process as if it were a regular file or a pipe that you can open and read from. /dev/stdout is a symbolic link to /proc/self/fd/1, which represents the standard output file descriptor of the current process. Thus, when a process writes to /dev/stdout, it's writing to its own standard output stream, and this stream is not directly accessible to other processes for reading in the way that a file or named pipe might be.
seems to work just fine for nginx https://github.com/railwayapp/nixpacks/blob/main/src/providers/php/nginx.template.conf#L18
@Josh Larson you got this working in the end? We run into the same issue where no Laravel logs appear.
@Pepijn I ended up sending my logs to a 3p store manually :/ I was just thinking though that you could theoretically wire up a multi-process manager and run
php artisan pail
to tail the logs to stdout along with the normal output. I haven't tried it yet thoughThanks for your reply. I eventually fixed got it to work by doing some config changes to the php-fpm conf I add in the docker image.