Skip to content

Instantly share code, notes, and snippets.

@bjornjohansen
Last active January 20, 2023 18:48
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save bjornjohansen/f4bd788d4d7a4172f5a9c539f4d09e47 to your computer and use it in GitHub Desktop.
Simple logging for WordPress
<?php
/**
* Simple logging for WordPress.
*
* @package BJ\Log
* @author bjornjohansen
* @version 0.1.0
* @license https://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU General Public License version 2 (GPLv2)
*/
if ( ! function_exists( 'write_log' ) ) {
/**
* Utility function for logging arbitrary variables to the error log.
*
* Set the constant WP_DEBUG to true and the constant WP_DEBUG_LOG to true to log to wp-content/debug.log.
* You can view the log in realtime in your terminal by executing `tail -f debug.log` and Ctrl+C to stop.
*
* @param mixed $log Whatever to log.
*/
function write_log( $log ) {
if ( true === WP_DEBUG ) {
if ( is_scalar( $log ) ) {
error_log( $log );
} else {
error_log( print_r( $log, true ) );
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment