WordPress.org

Make WordPress Core

Ticket #5669: 5669.r8535.patch

File 5669.r8535.patch, 4.6 KB (added by santosj, 6 years ago)

Updated WP_Logging API based off of r8535, uses pluggables instead.

  • wp-includes/functions.php

     
    23292329        return $url; 
    23302330} 
    23312331 
     2332/** 
     2333 * Whether custom logging should be enabled and register custom error handler. 
     2334 * 
     2335 * The custom error handler function name is called, 
     2336 * {@link wp_log_error_handler()} and should match the function definition 
     2337 * defined at {@link http://php.net/set_error_handler set_error_handler() PHP.net} 
     2338 * page. A plugin can replace the custom error handler, in order to save the 
     2339 * errors to a file or a database. The custom error handler can't handle E_ERROR 
     2340 * type errors and is a limitation of the PHP engine (mostly because it is going 
     2341 * to whitescreen and you can't do anything about it). 
     2342 * 
     2343 * This starts the custom error handling and goes along with the 
     2344 * {@link wp_stop_logging()} function when WordPress is complete. Plugins which 
     2345 * need to know when they should save the error reporting to file or database 
     2346 * should hook into 'wp_shutdown' hook in order to do so. If the plugin writes 
     2347 * whenever it gets an error, then it need not do so. 
     2348 * 
     2349 * @since {@internal Version Unknown}} 
     2350 * 
     2351 * @return bool True if logging, false if not logging. 
     2352 */ 
     2353function wp_start_logging() { 
     2354        if ( (has_filter('start_logging') && apply_filters('start_logging', true)) || (defined('WP_DEBUG') && true === WP_DEBUG ) ) { 
     2355                set_error_handler( 'wp_log_error_handler', E_ALL ); 
     2356                return true; 
     2357        } 
     2358 
     2359        return false; 
     2360} 
     2361 
    23322362?> 
     2363 No newline at end of file 
  • wp-includes/pluggable.php

     
    15801580} 
    15811581endif; 
    15821582 
    1583 ?> 
     1583if ( !function_exists( 'wp_log' ) ) : 
     1584/** 
     1585 * Log a message based on severity of the problem. 
     1586 * 
     1587 * The severity parameter accepts only 'notice', 'low', 'medium', 'warning', 
     1588 * 'high', and 'error' in that order of severity. 
     1589 * 
     1590 * @since {@internal Version Unknown}} 
     1591 * 
     1592 * @param string $type The area which the message was logged. 
     1593 * @param string $message The message to display to the user about the problem. 
     1594 * @param string $severity Severity level of the log message 
     1595 * @return bool False if failed to log message, true if message was logged. 
     1596 */ 
     1597function wp_log($type, $message, $severity) { 
     1598        echo "<p><strong>{$type}</strong> (<em>{$severity}</em>: $message</p>"; 
     1599        return true; 
     1600} 
     1601endif; 
     1602 
     1603if ( !function_exists( 'wp_plugin_log' ) ) : 
     1604/** 
     1605 * Log a plugin message based on severity of the problem. 
     1606 * 
     1607 * The severity parameter accepts only 'notice', 'low', 'medium', 'warning', 
     1608 * 'high', and 'error' in that order of severity. 
     1609 * 
     1610 * @since {@internal Version Unknown}} 
     1611 * 
     1612 * @param string $plugin Plugin Name 
     1613 * @param string $message The message to display to the user about the problem. 
     1614 * @param string $severity Severity level of the log message 
     1615 * @return bool False if failed to log message, true if message was logged. 
     1616 */ 
     1617function wp_plugin_log($plugin, $message, $severity) { 
     1618        echo "<p><strong>{$plugin}</strong> (<em>{$severity}</em>: $message</p>"; 
     1619        return true; 
     1620} 
     1621endif; 
     1622 
     1623if ( !function_exists( 'wp_log_error_handler' ) ) : 
     1624/** 
     1625 * Custom WordPress error handler. 
     1626 * 
     1627 * @param int $iError 
     1628 * @param string $strError 
     1629 * @param string $strFile 
     1630 * @param string $strLine 
     1631 * @param array $arrContext 
     1632 * @return bool 
     1633 */ 
     1634function wp_log_error_handler($iError, $strError, $strFile, $strLine, $arrContext) { 
     1635        $content = "<p>"; 
     1636 
     1637        if( defined('E_RECOVERABLE_ERROR') && E_RECOVERABLE_ERROR === $iError ) { 
     1638                $content .= "<strong>Recoverable Error</strong>: "; 
     1639                return true; 
     1640        } 
     1641 
     1642        switch( $iError ) { 
     1643 
     1644                case E_USER_ERROR: 
     1645                        $content .= "<strong>User Error</strong>: "; 
     1646                        break; 
     1647 
     1648                case E_USER_WARNING: 
     1649                case E_WARNING: 
     1650                        $content .= "<strong>Warning</strong>: "; 
     1651                        break; 
     1652 
     1653                case E_USER_NOTICE: 
     1654                case E_NOTICE: 
     1655                        $content .= "<strong>Notice</strong>: "; 
     1656                        break; 
     1657                default: 
     1658                        return false; 
     1659        } 
     1660 
     1661        $content .= "$strError found in <em>$strFile</em> on line <em>$strLine</em>.</p>"; 
     1662        echo $content; 
     1663 
     1664        return true; 
     1665} 
     1666endif; 
     1667 
     1668?> 
     1669 No newline at end of file 
  • wp-settings.php

     
    430430 
    431431require (ABSPATH . WPINC . '/pluggable.php'); 
    432432 
     433wp_start_logging(); 
     434 
    433435/* 
    434436 * In most cases the default internal encoding is latin1, which is of no use, 
    435437 * since we want to use the mb_ functions for utf-8 strings