Function to Write WordPress Log Messages

The following function helps you to write WordPress log messages. Arrays and objects will utilize print_r() to generate a readable output:

if ( ! function_exists( 'write_log' ) ) {
    function write_log( $log ) {
        if ( is_array( $log ) || is_object( $log ) ) {
            error_log( print_r( $log, true ) );
        } else {
            error_log( $log );
        }
    }
}

You can add this snippet to a custom plugin, so that all your themes and plugins might use the function.