Where should I tell WordPress where error_log messages should be written?

I have two different instances of the same server (one for development, one for deployment), built independently but basically the same (same OS, same WordPress version, same content etc.).

However, I’m confused about the configuration: it looks to me like they’re configured the same (except that the deployment server is told not to write errors/warnings to the browser).

Both configurations specify ini_set( 'error_log', '/var/log/wp-debug.log' ); and that file is indeed created by both; however, on one server anything written using error_log(...) goes to /var/log/wp-debug.log whereas on the other server, such output instead goes to /var/log/apache2/error.log (although PHP errors and warnings go to /var/log/wp-debug.log).

I’ve tried playing with the defined values of WP_DEBUG, WP_DEBUG_LOG and WP_DEBUG_DISPLAY as well as changing what display_errors is set to via ini_set(...) but nothing seems to make any difference.

Can I specify somewhere that I want the output of error_log(...) calls to go to one or other of these logs? (I’d like the output always to go to the Apache error.log because that extra information I want to use.)

2 Answers
2

On WP side the only handling it does is setting log to WP_CONTENT_DIR . '/debug.log' if WP_DEBUG_LOG is enabled (highly bad idea in production environment as public location). If I remember right the very early implementations of this constant allowed to customize the path, but that’s no longer the case.

In my experience ini_set( 'log_errors', 1 ); ini_set( 'error_log', '/path' ) in wp-config.php should be sufficient (if you don’t enable WP_DEBUG_LOG which will override it).

Your second case sounds strange. I would expect errors to go one destination or another, but not to two separate log files. It might be that something changes the configuration during runtime. It’s impossible to say without hands on troubleshooting.

Leave a Comment