WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] How to set a php error log file for WP?

[Resolved] How to set a php error log file for WP?

  • Hi All,

    I have been trying to set a error log file for my site.

    I have been through many tutorials but I am not getting what I want.

    i tried

    @ini_set('log_errors', 1);
    @ini_set('display_errors', 0); /* enable or disable public display of errors (use 'On' or 'Off') */
        @ini_set('error_log', dirname(__FILE__) . '/wp-content/logs/php-errors.log'); /* path to server-writable log file */
        @ini_set( 'error_reporting', E_ALL ^ E_NOTICE ); /* the php parser to  all errors, excreportept notices.  */

    but it didnt populate my php-errors.log file when i tried commiting some php errors.
    I checked the file permissions and it is writable.

    then i tried

    define('WP_DEBUG', true);
    if (WP_DEBUG) {
        define('WP_DEBUG_DISPLAY', false);
        /* log php errors */
        @ini_set('display_errors', 0); /* enable or disable public display of errors (use 'On' or 'Off') */
        @ini_set('error_log', dirname(__FILE__) . '/wp-content/logs/php-errors.log'); /* path to server-writable log file */
        @ini_set( 'error_reporting', E_ALL ^ E_NOTICE ); /* the php parser to  all errors, excreportept notices.  */
    }

    It worked, it populated the file with errors and warning but it didnt gave me the syntax error i have knowingly commited in a file.
    It should have given me a message like ” Parse error: syntax error, unexpected T_STRING in /var/www/project/misticks/wp-content/plugins/xyz-plugin/xyz.php on line 47

Viewing 12 replies - 1 through 12 (of 12 total)
  • Moderator keesiemeijer

    @keesiemeijer

    Not sure why the error is not showing up, but maybe set your error log like this:

    // Enable Debug logging to the /wp-content/debug.log file
    define('WP_DEBUG_LOG', true);

    http://codex.wordpress.org/Debugging_in_WordPress

    @keesiemeijer

    define('WP_DEBUG_LOG', true);

    helps u to log errors into the debug.log file in the wp-content but I have already set a error file to log errors and have given the path

    @ini_set('error_log', dirname(__FILE__) . '/wp-content/logs/php-errors.log'); /* path to server-writable log file */

    There must be another way. There must be something else that I am missing.

    Thanks for replying

    Moderator keesiemeijer

    @keesiemeijer

    Does the error show up if you don’t set WP_DEBUG_DISPLAY to false?

    // define('WP_DEBUG_DISPLAY', false);
    /* log php errors */
    // @ini_set('display_errors', 0); /* enable or disable public display of errors (use 'On' or 'Off') */

    How did you trigger the error?

    I tried taking off the whole line which means
    define(‘WP_DEBUG_DISPLAY’, true);

    Doing the above I get the same result as before and on top of the that the errors shows in my front end.

    FYI — i am only getting the php notices in the error log no warnings or errors

    Moderator keesiemeijer

    @keesiemeijer

    That’s strange. I created an error by putting this in my theme’s index.php and in an activated plugin:

    <?
    $error = "..."hello PHP Parse error";
    ?>

    With the exact same code as in your first posts in my wp-config.php I get an error log under /wp-content/logs/php-errors.log with this error in it:
    “PHP Parse error: syntax error, unexpected T_STRING in …”

    Try:

    – deactivating all plugins to see if this resolves the problem? If this works, re-activate the plugins one by one until you find the problematic plugin(s).

    – switching to the default theme to rule out any theme-specific problems.

    Did you try these set of codes

    @ini_set('log_errors', 1);
    @ini_set('display_errors', 0); /* enable or disable public display of errors (use 'On' or 'Off') */
    @ini_set('error_log', dirname(__FILE__) . '/wp-content/logs/php-errors.log'); /* path to server-writable log file */
    @ini_set( 'error_reporting', E_ALL ^ E_NOTICE );

    if yes what was the value you set for your WP_DEBUG.

    Can we set the error log files without setting WP_DEBUG to true?

    Moderator keesiemeijer

    @keesiemeijer

    In what file are you trying to do this? In your wp-config.php

    Did you try these set of codes

    I tried it with that set also. and it also works

    if yes what was the value you set for your WP_DEBUG.

    commented out like this:

    // define('WP_DEBUG', true);

    Can we set the error log files without setting WP_DEBUG to true?

    Yes I tried it with this (in wp-config.php), and it also works

    define('WP_DEBUG', false);
    @ini_set('log_errors', 1);
    @ini_set('display_errors', 0); /* enable or disable public display of errors (use 'On' or 'Off') */
    @ini_set('error_log', dirname(__FILE__) . '/wp-content/logs/php-errors.log'); /* path to server-writable log file */
    @ini_set( 'error_reporting', E_ALL ^ E_NOTICE );

    Moderator keesiemeijer

    @keesiemeijer

    Maybe your error handling is affected by the configuration of your server’s php.ini file. Ask your host about this if you’re not on a dedicated server.

    I am presently trying to use this in my local . Can you help me how to get this work in local.

    I tried the above codes in the wp-config.php

    and committed a syntax error in a plugin for which I got a error in my front end “Parse error: syntax error, unexpected T_STRING in /var/www/project/XYZ/wp-content/plugins/xyz-plugin/xyz.php on line 47 “

    but nothing gets write in the php error file inside wp-content/logs

    I have also tried the same in the dedicated server where my site is in but no luck.

    Moderator keesiemeijer

    @keesiemeijer

    Could you try it with only this in your wp-config.php:

    define('WP_DEBUG', false);
    @ini_set( 'error_reporting', E_ALL ^ E_NOTICE );

    And this at the bottom of your .htaccess:

    php_value log_errors 1
    php_value error_log /path/to/logs/php-errors.log

    change /path/to/logs/php-errors.log to the actual path (maybe: /var/www/project/misticks/wp-content/logs/php-errors.log).

    Hey this worked for me.
    Rather I didnt have a problem in the first place.
    The first set of codes used in config.php ie

    @ini_set('log_errors', 1);
    @ini_set('display_errors', 0); /* enable or disable public display of errors (use 'On' or 'Off') */
    @ini_set('error_log', dirname(__FILE__) . '/wp-content/logs/php-errors.log'); /* path to server-writable log file */
    @ini_set( 'error_reporting', E_ALL ^ E_NOTICE ); /* the php parser to  all errors, excreportept notices.  */

    is absolutely working.

    I was trying a wrong example to test the php error log.
    Anyways thanks for the help.

    Moderator keesiemeijer

    @keesiemeijer

    No problem.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘[Resolved] How to set a php error log file for WP?’ is closed to new replies.