Take the 2-minute tour ×

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

<?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 -->
error_log("File does not exist: " . rtrim($_SERVER['DOCUMENT_ROOT'], "/") . $_SERVER['REQUEST_URI'], 0);


// 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?

share|improve this question
add comment

1 Answer

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.

share|improve this answer
Hi thanks. This is useful, but my question is specific to 404 errors and failed login attempts I'm configuring fail2ban to block hacking attempts. So php errors won't do me any good. –  Sandro Dzneladze Jul 12 '12 at 12:11
add comment

Your Answer


