Tags: log,logging,debug,php,safari,firefox,firebug,firephp,console,development Requires at least: 2.5 Tested up to: 3.8.2 Stable tag: 0.4
Display log messages during plugin and theme development on the console in Safari and Firefox (with Firebug) browsers.
Forked from vicchi/wordpress-logger
Display log messages from PHP in the browser console in Safari, Firefox (with firebug), and Opera (with the new Dragonfly debugging environment). Essential debugging tool for plugin and theme developers. You no longer have to use 'print_r' statements from PHP to figure out what is going on in the code, which more often than not, messes up the DOM and HTML layout. Displays complex PHP structures like arrays and objects in pretty print.
- 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 ).
For more info, comments, and feature requests, visit the plugin homepage.
Installing from the Admin Panel
- Select the Add New subpanel from the Plugins panel.
- Type in "wordpress-logger" in the search field and click the Search button.
- Identify the "Wordpress Logger" from the plugin list and click on its install action.
- Click on the Install Now button in the resulting dialog.
- Click on the Activate Plugin link.
Installing manually
- Verify that you have PHP5, which is required for this plugin.
- Upload the whole wordpress-logger folder into the /wp-content/plugins/ directory.
- Activate the plugin through the Plugins panel 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:
- Firefox: The Firebug extension needs to be installed and activated.
- Safari: Show the Error Console from the Debug/Develop menu. See FAQ section for details on how to enable the Debug menu.
After activating the plugin, the following PHP function call can log any PHP expression to the console log.
$wplogger->log( php_expression [, message_type] );
$wplogger->log('Testing the plugin', WPLOG_INFO);
$wplogger->info('Testing the plugin');
$wplogger->debug('Testing the plugin');
$wplogger->warn('Testing the plugin');
$wplogger->error('Testing the plugin');
The message_type is optional and can be any one of the following constants:
- WPLOG_ERR
- WPLOG_WARNING
- WPLOG_INFO
- WPLOG_DEBUG
===
Logging from template files - 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 (e.g. 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.php] array (`
` 0 => 'wplogger/wplogger.php',`
` 1 => '12seconds-widget/12seconds-widget.php',`
` 2 => 'get-the-image/get-the-image.php',`
`)`
Logging from plugins - 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`
= How to enable the Debug / Develop menu in Safari? =
= How to show the error console in Opera? =
- Select the Tools > Advanced > Developer Tools menu.
- Click on the Error Console tab in the Opera Dragonfly console.
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.
0.3 : Added support for Opera ;
0.2.2 : Fixed formatting issues in readme.txt file;
0.2.1 : Added more detail to the readme.txt file;
0.2 : First official public release;
0.1 : First internal release;
- Test on chrome
- Test on WP 3.8.2
- Clean log message