make wordpress log errors in apache log file

I need to log 404 errors and wp-login failed attempts on wordpress site. Unfortunately it natively handles everything and doesn’t write to apache log file.

I tried this:
404.php

Read More
<?php get_header(); ?>
<div id="post-0" class="post error404 not-found">
    <h1><?php _e('Page Not Found', "magazine-basic"); ?></h1>
    <div class="storycontent">
        <p><?php _e('The page you requested could not be found.', "magazine-basic"); ?></p>
    </div><!-- .storycontent -->
</div><!-- #post-0 -->
<?php
error_log("File does not exist: " . rtrim($_SERVER['DOCUMENT_ROOT'], "/") . $_SERVER['REQUEST_URI'], 0);
get_footer();
?>

Functions.php

// Log login errors to Apache error log
add_action('wp_login_failed', 'log_wp_login_fail'); // hook failed login

function log_wp_login_fail($username) {
    error_log("WP login failed for username: $username");
}

But it doesn’t seem to do the trick. Any thoughts ideas how to do this?

Related posts

Leave a Reply

1 comment

  1. I use a separate error-log-file for WordPress that i add to wp-config.php like this:

    Step 1: Create a log file

    Create an empty file called “php-errors.log”. This file will serve as your site’s PHP error log. Your server will need write access to this file, so make sure to set the appropriate permissions.

    Step 2: Add the magic code

    Add this to wp-config.php after That's all, stop editing! Happy blogging.

    // log php errors
    @ini_set('log_errors','On'); // enable or disable php error logging (use 'On' or 'Off')
    @ini_set('display_errors','Off'); // enable or disable public display of errors (use 'On' or 'Off')
    @ini_set('error_log','/home/path/logs/php-errors.log'); // path to server-writable log file
    

    Once in place, edit the third line with the absolute directory path to the php-errors.log file created in the first step. Upload to your server and call it done. All PHP errors will now be logged to your php-errors.log file, thereby enabling you to monitor and resolve errors as quickly as possible.

    This trick is from diggwp. and there you can read more about solutions to handle errors in WordPress.