WP Debug Toolkit 1.1.0 is LIVE. Get $300 discount on the lifetime deal now
Use Discount Code WPDTLTD

WordPress debug.log grows continuously on active sites. Without management, a verbose site can accumulate hundreds of megabytes of log data, consuming disk space and making the log harder to navigate. WP Debug Toolkit (WPDT) provides automatic and manual cleanup to keep log files at a manageable size.

Automatic cleanup

WPDT schedules a daily cleanup task via WordPress cron (dbtk_daily_log_cleanup action). On each run, the task checks the error log age and size, then applies the configured cleanup method.

What triggers cleanup

Cleanup runs when either condition is met:

  • The log file is older than the configured retention period (in days)
  • The log file exceeds the configured maximum size (in MB)

Cleanup methods

Configure the cleanup method at Settings > Log Cleanup. Three methods are available:

Delete

Removes the entire debug.log file and creates a new empty one. No historical data is preserved. This is the most aggressive option and frees the most disk space.

Archive

Moves the current log file to a timestamped archive file (e.g., debug.log.old.2026-03-15), then creates a new empty debug.log. Archives are kept for a configurable number of days before being deleted automatically.

Use Archive when you need to preserve historical log data for later reference.

Truncate

Keeps the most recent portion of the log file and removes the rest. The amount to keep is configurable (in MB). A truncation marker is inserted at the top of the file to indicate that older content was removed.

Use Truncate when you want to maintain a rolling window of recent errors without creating separate archive files.

Manual cleanup

Three options for immediate cleanup:

Admin dashboard

Go to Settings > Log Cleanup and click the manual cleanup button. This runs the same cleanup logic as the daily cron, using your current settings.

Standalone viewer

Press Shift+R in the error log viewer. A confirmation dialog appears. Press Enter to confirm. This deletes the entire log file regardless of the configured cleanup method.

WP-CLI

wp dbtk log clear

This clears the debug log from the command line.

Query log cleanup

Query log files are stored separately from the error log, in wp-content/uploads/debug-toolkit/queries/ as monthly .log text files (e.g., queries-2026-03.log). Query log cleanup has its own retention setting and runs as part of the same daily cron task.

Query log cleanup uses a two-phase approach:

  1. Age-based — deletes query log files older than the retention period
  2. Size-based — if total query log size still exceeds the maximum, deletes the oldest remaining files until the total is under the limit

Configuration reference

All settings are accessible at Settings > Log Cleanup.

SettingDescriptionDefault
Error log retentionDays before the error log triggers age-based cleanup. Set to 0 to disable age-based cleanup.30 days
Query log retentionDays before query log files are removed. Set to 0 to disable.30 days
Max log sizeError log file size (MB) that triggers immediate truncation, regardless of age.50 MB
Query log max sizeTotal size (MB) for all query log files combined.100 MB
Cleanup methodHow old error logs are handled: Delete, Archive, or Truncate.Archive
Archive retentionDays to keep archived log files before deleting them. Only applies when cleanup method is Archive.90 days
Truncate keep sizeAmount of recent data (MB) to preserve when truncating. Only applies when cleanup method is Truncate.10 MB

Note: Setting retention to 0 days disables age-based cleanup for that log type. Size-based limits still apply.

Cron considerations

The dbtk_daily_log_cleanup action relies on WordPress cron, which is triggered by site visitors. On low-traffic sites, cron events may run late. If reliable scheduling is important, configure a system-level cron job to trigger WordPress cron:

# Run WordPress cron every hour via system crontab
0 * * * * cd /path/to/wordpress && wp cron event run --due-now

On this page
Try WP Debug Toolkit
The best error log viewer with amazing developer tools to help you troubleshoot your WordPress site securely and efficiently. Something something more.