I want to log some messages from my php application in the apache error logs. But I would like this to happen only in the non-production environments.
I found that php has error_log
to log messages to the error log file but how do I control it to only log if my application is running in the non-prod environments.
Also, I found that there is trigger_error
which takes a error type
parameter. And the error_reporting
setting in php.ini can then decide which error types are actually logged. So, while in dev, I have error_reporting set to E_ALL
, it is more restricted in production. So, now I can use trigger_log and always log at E_USER_NOTICE
. This would mean that my message is only shown in the dev log files but not in the production log files.
However, trigger_error also produces a stack trace with every log which is a bit unnecessary for me. How can I disable this stack trace.
Also, am I doing things the right way. How do people generally handle this problem.
Edit: I am not trying to suppress error messages. I am trying to provide more debug messages in dev . Things like "Request came with following parameters", "step 1 done", etc. This is really not required in production.
Firstly, suppressing error handling is not a good idea - errors have a huge impact on your application performance - and suppressing error reporting does not eliminate the slowdown.
There is no 'trigger_log' in PHP.
The build in error handling in PHP does not generate a stack trace - you must have a custom error handler installed. You need to find it and amend the code if you want to change it's behaviour.
Using 'trigger_error' to record debug events is a very bad idea.
如果只想将自定义消息手动发送到错误日志,则log_error()
是您要查找的函数。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.