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