Bang System Logging
Enable system logging for WordPress plugin and theme development. This can make it easier to know what your code is doing. Features include: Log to the system log or to a file Easily append or embed any value in log messages Coloured logs indicating strings, numbers, arrays, objects, null values etc
About this tool.
Enable system logging for WordPress plugin and theme development. This can make it easier to know what your code is doing.
Features include:
- Log to the system log or to a file
- Easily append or embed any value in log messages
- Coloured logs indicating strings, numbers, arrays, objects, null values etc.
- Extract values from arrays of objects
- Optionally exclude AJAX, Javascripts, CSS and any other pattern of URLs.
- Intercept PHP errors and log strict warnings
- Measure memory usage between two points, or the time taken by various parts of your code
- Easy to switch off for production sites
How to use
Using it is as simple as calling the 'log' action in your templates or plugin.
<?php do_action('log', 'Some log message'); ?>
This will produce a line in your system log:
Jun 4 11:23:08 myserver php/mysite.com[1553]: b8e mysite.com/path-to-page: Some log message
This includes:
- Jun 4 11:23:08 – The date and time of the log message
- myserver – The name of this computer
- php – The program that produced the message
- mysite.com – The domain name of the site
- 1553 – The process ID of the running PHP process
- b8e – A random 3-digit code identifying each page request
- mysite.com/path-to-page – The URL of the request
- Some log message – Your message
For more detailed instructions, see the How to use tab.
How to use
To log a message, use the 'log' action in your templates or plugins:
<?php do_action('log', 'Some log message'); ?>
This will output the log message:
Some log message
Embedding values
If you include extra parameters, they’ll be added at the end of the log message:
<?php do_action('log', 'A number and a string', 17, 'foo'); ?>