• Georg

    (@georgwordpress)


    Since wp 6.6, after every automtic plugin update/upgrade, the WP Debug log is filled with
    “scraping home page… “
    followed by the whole html body text.


    [29-Aug-2024 22:24:01 UTC] Automatic updates starting...
    [29-Aug-2024 22:24:02 UTC] Automatic plugin updates starting...
    [29-Aug-2024 22:24:02 UTC] Upgrading plugin 'advanced-custom-fields-pro'...
    [29-Aug-2024 22:24:05 UTC] Plugin 'advanced-custom-fields-pro' has been upgraded.
    [29-Aug-2024 22:24:07 UTC] Scraping home page...
    [29-Aug-2024 22:24:07 UTC] '<!doctype html>
    <html lang="de">
    <head>
    ...
    [29-Aug-2024 22:24:07 UTC] The update for 'advanced-custom-fields-pro' has no fatal errors.
    [29-Aug-2024 22:24:07 UTC] Automatic plugin updates complete.
    [29-Aug-2024 22:24:07 UTC] Automatic updates complete.

    Apparently the scraping is related to the rollback auto-update feature introduced in wp 6.6.
    But how to prevent the debug log from being filled up with the html body after every automatic plugin update/upgrade?

Viewing 6 replies - 1 through 6 (of 6 total)
  • The issue you’re encountering seems to stem from WordPress 6.6’s auto-update and rollback feature that scrapes the homepage to ensure that everything works properly after an automatic update. While this is useful for debugging purposes, it is indeed unnecessary to log the entire HTML of your home page to the debug log after every update.

    To resolve this issue, we can adjust the behavior by either preventing the homepage scraping from being logged or suppressing these specific debug entries. Here are two approaches to deal with this issue:

    1. Disable Scraping Logging in Debug Log

    You can add a filter to prevent logging the scraped HTML output after a plugin update. WordPress offers hooks and filters that you can use to customize its behavior.

    Add the following code to your theme’s functions.php file or a custom plugin:

    // Disable logging of scraping output after automatic updates.
    add_filter('automatic_updates_debug', function($log_entry, $context) {
    if (strpos($log_entry, 'Scraping home page...') !== false) {
    // Prevent logging of the HTML body.
    return false;
    }
    return $log_entry;
    }, 10, 2);

    This code checks if the log entry contains the “Scraping home page…” text and stops that entry from being logged by returning false.

    2. Reduce WordPress Debug Log Verbosity

    If you don’t need detailed debug information for automatic updates, you can reduce the verbosity of the debug log in general.

    In wp-config.php, you can turn off the debug log or only log certain types of errors:

    // Disable WP_DEBUG_LOG or set it to a more restrictive mode.
    define('WP_DEBUG', true);
    define('WP_DEBUG_LOG', true);
    define('WP_DEBUG_DISPLAY', false);

    // Disable notices and only log errors and warnings
    define('WP_DEBUG_LEVEL', E_ERROR | E_WARNING);

    This reduces the amount of information logged, including potentially the full HTML scrape output. However, this method may suppress other useful debug information, so it is recommended only if you don’t require extensive logging.

    Thread Starter Georg

    (@georgwordpress)

    Wow – thanks for the quick response!
    The filter is the solution I was looking for.

    Thread Starter Georg

    (@georgwordpress)

    I am confused – I could not find this filter:
    “automatic_updates_debug”

    I found only this filter:
    ‘automatic_updates_debug_email’

    https://github.com/WordPress/WordPress/blob/6.6-branch/wp-admin/includes/class-wp-automatic-updater.php

    You’re correct. Upon reviewing the WordPress core files, it seems there is no automatic_updates_debug filter in the WordPress codebase, but there is indeed an automatic_updates_debug_email filter, which controls debug messages sent via email after automatic updates.

    To specifically suppress the scraping of the homepage without affecting other debug features, there is no direct filter provided in the current WordPress core. However, we can address the issue by intercepting the output in a custom manner, using available hooks around the automatic update process.

    Here’s an approach to filter out unwanted logs related to the homepage scraping:1. Intercept Debug Logs with a Custom Error Handler

    We can create a custom error handler to capture the log entries and filter out the scraping message before it’s written to the log file.

    You can add the following code to your theme’s functions.php file or a custom plugin:

    // Custom error handler to filter out scraping logs.
    add_action('init', function () {
    // Check if WP_DEBUG is enabled.
    if (defined('WP_DEBUG') && WP_DEBUG && defined('WP_DEBUG_LOG') && WP_DEBUG_LOG) {
    // Set a custom error handler.
    set_error_handler('filter_scraping_debug_log', E_USER_NOTICE | E_USER_WARNING | E_USER_ERROR);
    }
    });

    // Custom function to filter the scraping log entry.
    function filter_scraping_debug_log($errno, $errstr, $errfile, $errline) {
    // Filter out the "Scraping home page" log entry.
    if (strpos($errstr, 'Scraping home page...') !== false || strpos($errstr, '<!doctype html>') !== false) {
    // Prevent logging of this particular message.
    return true; // Returning true prevents the default error handler from continuing.
    }

    // Let other messages pass through.
    return false; // Returning false lets the normal error handler proceed.
    }

    How This Works:

    1. Custom Error Handler: We are using set_error_handler() to define a custom error handler that intercepts messages before they are logged.
    2. Filter Logic: The handler checks if the error message contains Scraping home page... or an HTML doctype (<!doctype html>), and if so, prevents it from being logged.
    3. Fallback for Other Logs: Other debug messages will pass through as usual and be handled by WordPress’s default logging mechanism.

    2. Disable Update Rollback Feature (Optional)

    If you do not require the rollback feature introduced in WordPress 6.6, you could disable it altogether by adding the following line to your wp-config.php file:

    // Disable the rollback feature.
    define('WP_AUTO_UPDATE_ROLLBACK', false);

    This will stop WordPress from scraping the homepage after updates, which in turn prevents the related logs from being generated.

    Thread Starter Georg

    (@georgwordpress)

    Ok Will check that for sure

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Every Plugin Upgrade fill Debug Log with Scraping home page…’ is closed to new replies.