Skip to content

Instantly share code, notes, and snippets.

@jcamp
Created August 13, 2018 16:45
Show Gist options
  • Save jcamp/aa4e0200c452bc75768fab226c48d3a1 to your computer and use it in GitHub Desktop.
Save jcamp/aa4e0200c452bc75768fab226c48d3a1 to your computer and use it in GitHub Desktop.
Very simple logging to a file by calling 'write_log' in our php code (wordpress edition)
<?php
// Taken pretty much from https://www.elegantthemes.com/blog/tips-tricks/using-the-wordpress-debug-log
// error_log info on php site - http://php.net/manual/en/function.error-log.php
// Just stick this function in your functions.php if you like :)
if ( ! function_exists('write_log')) {
function write_log ( $log ) {
if ( is_array( $log ) || is_object( $log ) ) {
// error_log - Sends an error message to the web server's error log or to a file.
error_log( print_r( $log, true ) );
$to = "your_email@your_domain.com";
$subject = date("Y-m-d h:i:sa")." :: Logging for Relocate Homes";
$content = print_r( $log, true );
$status = wp_mail($to, $subject, $content);
} else {
error_log( $log );
$to = "your_email@your_domain.com";
$subject = date("Y-m-d h:i:sa")." :: Logging for Relocate Homes";
$content = $log;
$status = wp_mail($to, $subject, $content);
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment