Skip to content

Tareq Hasan

Posted on

A file based logging utility

We all do debugging. I frequently use a file based logging function that I wrote, it was very basic. Thought it could be more improved, so here’s the improved version.

It has a small dependency, WordPress’s WP_CONTENT_DIR constant, because I do WordPress a lot. But you can change the logging file path as you want.

Usage:

Drop the function anywhere in your theme/plugin. The preferred way would be using it in your MU plugin.

$simple_var = 'dynamic variable';
$test_array = array('one' => 'One', 2, '3');

wp_log( 'test', 'a simple string for testing');
wp_log( 'test', 'A simple variable: ', $simple_var );
wp_log( 'sms', 'It\'s an array: ', $test_array );
wp_log( 'truth', 'A boolean True value: ', true );
wp_log( 'test', 'It should be false: ', false );
wp_log( 'group', 'PHP object: ', $post );

PHP file based Logging screenshot

2 thoughts on “A file based logging utility”

  1. Hi, i read your blog occasionally and i own a similar one and i was just wondering if you get a lot of spam feedback? If so how do you stop it, any plugin or anything you can recommend? I get so much lately it's driving me mad so any assistance is very much appreciated.