[英]Why Symfony dies with a 500 error without Monolog writing anything to the log file?
I'm attempting to have more information on production when my site errors out.当我的网站出错时,我试图获得更多关于生产的信息。 The scenario is this:
场景是这样的:
We integrate with stripe, and stripe webhooks to do certain calls.我们与 stripe 和 stripe webhooks 集成以进行某些调用。 When a stripe function fails, we don't have any information to understand what went wrong on our production server.
当条带 function 失败时,我们没有任何信息来了解生产服务器上出了什么问题。 Currently stripe returns this sort of error:
目前 stripe 返回这种错误:
It's unhelpful for sure, but my hope is that the prod.log
file within var/log/prod.log
file would have information.这肯定没有帮助,但我希望
var/log/prod.log
prod.log
中的 prod.log 文件会有信息。 I take a look and it's empty (not ideal - now we don't know what the problem is at all).我看了一下,它是空的(不理想——现在我们根本不知道问题出在哪里)。
My monolog.yaml
file for production is as follows:我用于生产的
monolog.yaml
文件如下:
monolog:
handlers:
filter_for_errors:
type: fingers_crossed
# if *one* log is error or higher, pass *all* to file_log
action_level: error
handler: file_log
# now passed *all* logs, but only if one log is error or higher
file_log:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
# still passed *all* logs, and still only logs error or higher
syslog_handler:
type: syslog
level: error
This is standard, straight from the docs, however, it still seems as though nothing is getting written to that file.这是标准的,直接来自文档,但是,似乎没有任何内容写入该文件。
I'm checking permissions for that file:我正在检查该文件的权限:
-rw-r--r-- 1 deploy www-data 488007 Mar 2 19:21 prod.log
Are those the right permissions?这些是正确的权限吗?
Does my nginx server block configuration need to point to the right file as well or is symfony enough for this?我的 nginx 服务器块配置是否也需要指向正确的文件,或者 symfony 是否足够?
That file should be writtable by the same user who owns the webserver process.该文件应该可以由拥有网络服务器进程的同一用户写入。 It's usually
www-data
, but check your server configuration.它通常是
www-data
,但请检查您的服务器配置。
Usually everything under var
should be writable by the web-server process.通常
var
下的所有内容都应该可以被网络服务器进程写入。
Checking the docs about the recommended directory permissions for a Symfony project is always a recommended course of action in case of doubt.检查有关 Symfony 项目的推荐目录权限的文档始终是在有疑问时推荐的操作过程。
Also, trying to replicate the production environment as closely as possible on dev and on production.此外,尝试在开发和生产中尽可能接近地复制生产环境。 If you reproduced this issue on development, you could have enabled
display_errors
on PHP and you'd see the ultimate cause.如果您在开发中重现了这个问题,您可以在 PHP 上启用
display_errors
并且您会看到最终原因。
What's happening here is that when anything that triggers writing to the log happens, the application will encounter a fatal error because it can't write the the log files.这里发生的事情是,当任何触发写入日志的事情发生时,应用程序将遇到致命错误,因为它无法写入日志文件。 So even if the original error was non-fatal, even a warning or informational, it gets escalated to a
500
because not being able to write to a location where the application expects to, it's a non-recoverable error.因此,即使原始错误不是致命错误,即使是警告或信息性错误,它也会升级为
500
,因为无法写入应用程序期望的位置,这是一个不可恢复的错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.