I have a Symfony application and I have set a request_terminate_timeout = 60 to be the same as Nginx timeout, and afterwords for 504 requests I can’t see production logs, but if I use prod env locally I can see the logs. Logs are written to php://stdout
In the monolog config, I use the stream handler, so it should not use any buffer but immediately send logs to tty, and locally it send logs right away (again, locally I tested it with prod env), so everything should be fine, right? Here is the Monolog config:
monolog:
handlers:
main:
type: stream
path: "%log_path%"
level: info
channels: ["!event"]
console:
type: console
process_psr_3_messages: false
channels: ["!event", "!doctrine"]
deprecation:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.deprecations.log"
deprecation_filter:
type: filter
handler: deprecation
max_level: info
channels: ["php"]
Logpath value:
parameters:
log_path: "%env(string:default:default_log_path:LOG_DESTINATION)%"
And log destination is equal to php://stdout
Also for the sake of the test, I add logs directly to index.php to omit framework and monolog, like this
(new Dotenv())->bootEnv(dirname(__DIR__) . '/.env');
$logFile = isset($_SERVER['LOG_DESTINATION']) && $_SERVER['LOG_DESTINATION'] !== ''
? $_SERVER['LOG_DESTINATION']
: 'php://stdout';
try {
file_put_contents(
$logFile,
json_encode(
[
'datetime' => (new DateTimeImmutable())->format('Y-m-dTH:i:s.uP'),
'message' => 'Request init.',
],
JSON_THROW_ON_ERROR,
) . PHP_EOL,
FILE_APPEND,
);
} catch (Throwable $e) {
file_put_contents(
$logFile,
'{"message" : "Error writing logs. ' . $e->getMessage() . '."}' . PHP_EOL,
FILE_APPEND,
);
}
register_shutdown_function(
static function () use ($requestId, $logFile, $start): void {
$errorArray = error_get_last();
try {
file_put_contents(
$logFile,
json_encode(
[
'datetime' => (new DateTimeImmutable())->format('Y-m-dTH:i:s.uP'),
'message' => 'Request finished.',
'last_error' => is_array($errorArray) ? $errorArray : [],
'execution_time_ms' => round((microtime(true) - $start) * 1000),
],
JSON_THROW_ON_ERROR,
) . PHP_EOL,
FILE_APPEND,
);
} catch (Throwable $e) {
file_put_contents(
$logFile,
'{"message" : "Error writing logs. ' . $e->getMessage() . '."}' . PHP_EOL,
FILE_APPEND,
);
}
},
);
again I do not see those logs in production, but locally I can see all the logs including this new added to index.php. Maybe there is a config on the PHP level that controls some buffer or something like that?? Why locally with prod env I see those logs, but on production (that actually uses the same docker image) I see only the Nginx log of about 504 but nothing from the application side? Thanks in advance!