PHP: merge all error_log files in to a single file

2019-09-11 13:45发布

问题:

This question is an exact duplicate of:

  • PHP: scan all directories/folders for instances of PHP “error_log” files

Is it possible to edit the php.ini file (or anything else) and have all the *php_log* files be merged in to a single php_log file instead of one per directory?

Clarification for those who don't actually read: scanning a directory for a file type and merging files are two VERY separate actions with very different answers. Apparently the dup reporters NEVER asked two questions about a topic ever. >__>

回答1:

You're looking for the error_log directive from the php.ini file.

The value must be an absolute path to the file where you wish the errors to be logged. If it's relative, PHP will create that file in the directory where the script exists (the one in which the error came up). That's probably the reason why you have error_logs in each directory :)

As a side node, if you don't have access to the configuration file, it's possible to change this setting at runtime. Something like ini_set('error_log', __DIR__ . '/errors'); in your index.php script



回答2:

If you want to have all the "error reports" in one file (txt for example). Create a txt file and write there the result of an error handler along with other info like date etc. That way, every time that an error occurs the msg will be written in this unique file.