Skip to content
Snippets Groups Projects

Simple Debug Log for WP

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by Rolf Forst

    debug_log (mixed $message) : bool

    Utility function to write the debug log to the PHP's system logger file.

    The constant WP_DEBUG must be true in order to write to the log file.

    If the WP_DEBUG_LOG constant is also set to true, the log is saved to wp-content/debug.log

    Use 'tail' to view the log in realtime in the terminal e.g. 'tail -f wp-content/debug.log'

    Edited
    debug-log.php 433 B
    <?php
    
    if (!function_exists('debug_log')) {
        /**
         * Write the debug log to the error log file.
         * @param mixed $message Debug log.
         * @return bool
         */
        function debug_log($message) {
            if (true === WP_DEBUG) {
                if (is_scalar($message)) {
                    return error_log($message);
                } else {
                    return error_log(print_r($message, true));
                }
            }
        }
    }
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment