I've run into some issues lately trying to log from PHP-FPM inside a Docker container and I'm curious what's the best way to handle the situation, and if this is an area where PHP-FPM might be improved. If there's someone or somewhere else I should ask, please let me know.
Question: Is there any way to format the error log, particularly to allow stdout of child workers to pass through unaltered?
In a single a container, I have to run PHP-FPM and my PHP app, both of which have logs. The normal Docker way, and in my opinion the easiest way for standardized log collection, is to send all logging to stdout. That's not a problem for PHP-FPM--I can easily send its error and access logs to stdout and stderr, which are then collected by docker log or any other collector.
However, the only way to output my app's logs is to enable "catch_workers_output", which presents two difficulties: 1) My app's stdout is wrapped in quotes and prefixed with "WARNING: [pool www] child 11606 said into stdout:". 2) Each line of output is presented as a separate log entry, making stack traces difficult to follow.
I realize I could have my app log directly to some outside collector, but that breaks the encapsulation and portability of my container, and would increase the complexity of a development environment.
Ideally, I'd have my app output JSON log entries that could be captured by PHP-FPM and entered into its log without any alteration, thus enabling me to pass them in their original form to whatever log aggregation service I use. Is there any way to do that? If not, is that something that could be added to PHP-FPM?