The Problem

When WP_DEBUG_LOG is enabled, WordPress logs all PHP errors, notices, and deprecation warnings to wp-content/debug.log. Over time, repetitive warnings from plugins and themes can cause this file to grow to gigabytes, consuming all available disk space.

Symptoms

  • debug.log file is several GB in size
  • Disk space warning on the server
  • df -h shows root partition is full
  • Same warning repeated millions of times
  • Site slows down due to disk I/O

Real Log Content

bash
[09-Apr-2026 10:15:22 UTC] PHP Deprecated:  str_pad(): Passing null to
parameter #1 ($string) of type string is deprecated in
/wp-content/plugins/old-plugin/functions.php on line 142
[09-Apr-2026 10:15:22 UTC] PHP Deprecated:  str_pad(): ... (REPEATED 50,000 TIMES)

How to Fix It

Fix 1: Truncate the Log File

```bash # Truncate without deleting the file > wp-content/debug.log

# Or use truncate command truncate -s 0 wp-content/debug.log

# Check file size ls -lh wp-content/debug.log ```

Fix 2: Set Up Log Rotation

bash
# /etc/logrotate.d/wordpress-debug
/var/www/html/wp-content/debug.log {
  daily
  rotate 7
  compress
  delaycompress
  missingok
  notifempty
  size 100M
  create 644 www-data www-data
}

Fix 3: Filter Specific Deprecation Warnings

php
// functions.php - Suppress specific deprecation warnings
set_error_handler(function($severity, $message, $file, $line) {
  if ($severity === E_DEPRECATED && strpos($message, 'str_pad()') !== false) {
    return true; // Suppress this specific warning
  }
  return false; // Let WordPress handle other errors
});

Fix 4: Use Error Log with Size Limit

```php // Custom debug log with size check add_action('init', function() { $log_file = WP_CONTENT_DIR . '/debug.log'; $max_size = 10 * 1024 * 1024; // 10MB

if (file_exists($log_file) && filesize($log_file) > $max_size) { // Rotate: rename old log, create new one rename($log_file, $log_file . '.old'); } }); ```

Fix 5: Fix the Underlying Deprecation

```bash # Find the source of deprecation warnings grep -r "str_pad.*null" wp-content/plugins/

# Update the plugin or replace the deprecated function # In PHP 8.1+, str_pad(null, ...) is deprecated # Fix: str_pad((string)$value, 10, '0', STR_PAD_LEFT) ```

Fix 6: Configure PHP Error Reporting Level

```php // wp-config.php define('WP_DEBUG', true); define('WP_DEBUG_LOG', true); define('WP_DEBUG_DISPLAY', false);

// Only log errors and warnings, not deprecations ini_set('error_reporting', E_ALL & ~E_DEPRECATED & ~E_NOTICE); ```

Fix 7: Monitor Log Size Automatically

bash
# Add to crontab
0 * * * * find /var/www/html/wp-content -name "debug.log" -size +100M -exec truncate -s 0 {} \;