0

We currently have this config for our logging in our wordpress wp-config.php file

define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
@ini_set( 'display_errors', 1 );
@ini_set( 'log_errors', 1 );
@ini_set( 'error_log', dirname(__FILE__) . '/wp-content/debug.log' );

I'm wondering is there a way to get wordpress to create a distinct log file per day. In java land and log4j, there is a RollingDailyFileLogger which renames the log file at mid-night.

Is there any package or library which would allow be to define the wordpress debug file in this format

@ini_set( 'error_log', dirname(__FILE__) . '/wp-content/${YYYY-MM-DD}-debug.log' );

Thanks

EDIT - I have one idea to setup a wordpress cron job which would be scheduled to run at midnight. The job would rename the existing 'debug.log' file with the previous dates daystamp and assume the error_log() would recreate the file. Not the nicest but it might work.

2

Well, yes - there is such way. And you even have the solution already in your code...

Even more - you almost solved it yourself...

This line decides, where the log will be located:

@ini_set( 'error_log', dirname(__FILE__) . '/wp-content/debug.log' );

So all you need is to add date in that file name. Like this:

@ini_set( 'error_log', dirname(__FILE__) . '/wp-content/' . date('Y-m-d') . '-debug.log' );

As you can see no cron is needed to achieve this ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.