Essential debugging tool for plugin and theme developers.
Display log messages from PHP in the browser console in Safari and Firefox (with firebug). You no longer have to use print_r statements from PHP to figure out what is going on in the code. Besides, print_r statements mess up the DOM and HTML layout.
Features
- Log debug messages directly from themes and plugins.
- Display log messages in the browser console, without muddying up the browser display.
- Displays complex structures such as arrays and objects in pretty print.
- Shows the line number and file from where the message was logged ( you won’t lose track of log statements ).
Screenshots
Installation
- Verify that you have PHP5, which is required for this plugin.
- Download the whole
wploggerfolder into the/wp-content/plugins/directory. - Activate the plugin through the Plugins menu in WordPress.
Requirements
- Make sure that your theme template has a footer ( index.php should have a get_footer() function call at the end).
- Turn on the console in your browser:
Usage
After activating the plugin, the following PHP function call can log any PHP expression to the console log.
$wplogger->log( php_expression [, message_type] );
The message_type is optional and can be any one of the following constants:
- WPLOG_ERR
- WPLOG_WARNING
- WPLOG_INFO
- WPLOG_DEBUG
Use cases
Logging from template files
This is from inside the loop to display post IDs.
<?php $wplogger->log( 'Post ID: '.$post->ID ); ?>
Output:
[Information: from line 20 in file index.php] Post ID: 125 [Information: from line 20 in file index.php] Post ID: 116 [Information: from line 20 in file index.php] Post ID: 65
Logging from PHP files
This is from functions.php ( always a good idea to check if $wplogger is available ). Note the message type set to warning through the second parameter.
if ($wplogger) $wplogger->log( get_option('active_plugins'), WPLOG_WARNING );
Output:
[Warning: from line 55 in file functions.<span>php</span>] array ( 0 => 'wplogger/wplogger.php', 1 => '12seconds-widget/12seconds-widget.php', 2 => 'get-the-image/get-the-image.php', )
Logging from plugins
This is from inside a plugin function. Note the global statement to get $wplogger into current scope.
global $wplogger; $wplogger->log( 'No images attached to this post', WPLOG_ERR );
Output:
[Error: from line 206 in file get-the-image.php] No images attached to this post
Credits
Code that forces the wplogger plugin to load first was adapted from the WordPress FirePHP plugin developed by Ivan Weiller.
This plugin is based on PEAR Log, the logging framework that is part of the PHP PEAR library. Current maintainers Jon Parise, Jan Schneider, and Chuck Hagenbuch. PEAR Log is based on code first developed for the Horde 1.3 framework – original authors Chuck Hagenbuch, and Jon Parise.
Download Plugin
Feature requests and critiques
This is the first iteration of the wplogger plugin. Please comment on how you would like to see it improved.


What an excellent plugin! Any chance of this working with Opera Dragonfly soon too? Thank you for sharing
@RavanH thanks for bringing Opera Dragonfly to my attention. It’s been quite a while since I’ve fired up an Opera Browser, but I’ll certainly look into integrating it. Glad you like the plugin.
@RavanH I’ve added support for Opera. Log messages are now visible on the Opera Dragonfy error console in version 0.3 of the plugin. Please provide some feedback on performance as I didn’t have much time for comprehensive testing on Opera.
It works! No issues whatsoever
One question though: Right now it displays error logging to any visitor (visible either in source code or on error console) but would it be safer to log only to admin? And maybe make it optional (with a warning) to log other users?
Hi RavanH, Thanks for checking it out. Logging only if admin was part of future functionality. I’ll implement it ASAP.
Cool plugin!
I’m using wplogger on v2.8.4 and No error was occured.
@tf0054 thanks for testing the plugin on the latest version of WP.
Hi,
You might want to register the `flushLogMessages` function with the `admin_footer` action hook, too. Otherwise it doesn’t work in the admin area for me:
—
# MOD:: register admin footer, too:
add_action( ‘admin_footer’, array($wplogger, ‘flushLogMessages’) ); // log scripts
—
Other than that it works great
Take care,
Aleksandar
Not working in plugin page.
global $wplogger; $wplogger->log( ‘No images attached to this post’, WPLOG_ERR );
At $wplogger information is present, but Firebug does not display debug information.
plugin not working if WP root directory is a subfolder eg http://exemple.com/WPress/
@Pitschi I’m not sure why it doesn’t work with a WP subfolder install. The only directory dependency is a
plugin_basename( __FILE__ )call in the methods that re-order the plugin list. Anybody know if theplugin_basenamefunction breaks on a subfolder install? Or could it be some other issue?plugin_basename( __FILE__ ) should not cause any problem on a subfolder install… been looking through the code a bit but cannot find anything that would explain this. no get_option(‘site_url’ / ‘home’) mixup no hardcoded paths (as far as I could see)… weird.
the only thing I noticed is wp_enqueue_script( ‘jquery’, ’1.2,6′ ) , should that not be wp_enqueue_script( ‘jquery’, ’1.2.6′ ) ?
Unfortunatly it does not work when page redirection is involved
A subfolder install did not cause me any problems.
How about some more examples?
Thank you!
Great Plugin. The best of all the WP logging I’ve tried.
Great information for us. Thanks
Hi
I’m trying a few debugging tools in order to try and resolve an issue with some custom settings code I have added to add custom settings within the admin section for a new page. http://wefunction.com/2008/10/tutorial-creating-custom-write-panels-in-wordpress/. So far I have got further with this method and can return some values. But in some areas of the functions.php code it returns nothing. I’m I missing something.
Rob
@Rob, It could be that the $wplogger variable is out of scope. Did you try:
global $wplogger; $wplogger->log( ‘testing’, WPLOG_WARNING );
[...] WordPress Logger [...]