Version: 0.4, Last Updated: 6/22/2010
Tested with Internet Explorer 6-8, Firefox 3-3.6, Safari 3-4, Chrome 3-5, Opera 9.6-10.5
JavaScript Debug: A simple wrapper for console.log | Version: 0.4, Last Updated: 6/22/2010 |
License | Copyright © 2010 “Cowboy” Ben Alman, Dual licensed under the MIT and GPL licenses. |
Support and Testing | Information about what browsers this code has been tested in. |
Examples | These working examples, complete with fully commented code, illustrate a few ways in which this plugin can be used. |
Revision History | |
Pass-through console methods | assert, clear, count, dir, dirxml, exception, group, groupCollapsed, groupEnd, profile, profileEnd, table, time, timeEnd, trace |
Functions | |
debug.log | Call the console.log method if available. |
debug. | Call the console.debug method if available, otherwise call console.log. |
debug.info | Call the console.info method if available, otherwise call console.log. |
debug.warn | Call the console.warn method if available, otherwise call console.log. |
debug. | Call the console.error method if available, otherwise call console.log. |
debug. | Set a minimum or maximum logging level for the console. |
debug. | Set a callback to be used if logging isn’t possible due to console.log not existing. |
Copyright © 2010 “Cowboy” Ben Alman, Dual licensed under the MIT and GPL licenses. http://benalman.com/about/license/
These working examples, complete with fully commented code, illustrate a few ways in which this plugin can be used.
Examples | http://benalman.com |
assert, clear, count, dir, dirxml, exception, group, groupCollapsed, groupEnd, profile, profileEnd, table, time, timeEnd, trace
These console methods are passed through (but only if both the console and the method exists), so use them without fear of reprisal. Note that these methods will not be passed through if the logging level is set to 0 via debug.setLevel.
Call the console.log method if available. Adds an entry into the logs array for a callback specified via debug.setCallback.
debug.log( object [, object, ...] ); | - |
object | (Object) Any valid JavaScript object. |
Call the console.debug method if available, otherwise call console.log. Adds an entry into the logs array for a callback specified via debug.setCallback.
debug.debug( object [, object, ...] ); | - |
object | (Object) Any valid JavaScript object. |
Call the console.info method if available, otherwise call console.log. Adds an entry into the logs array for a callback specified via debug.setCallback.
debug.info( object [, object, ...] ); | - |
object | (Object) Any valid JavaScript object. |
Call the console.warn method if available, otherwise call console.log. Adds an entry into the logs array for a callback specified via debug.setCallback.
debug.warn( object [, object, ...] ); | - |
object | (Object) Any valid JavaScript object. |
Call the console.error method if available, otherwise call console.log. Adds an entry into the logs array for a callback specified via debug.setCallback.
debug.error( object [, object, ...] ); | - |
object | (Object) Any valid JavaScript object. |
Set a minimum or maximum logging level for the console. Doesn’t affect the debug.setCallback callback function, but if set to 0 to disable logging, Pass-through console methods will be disabled as well.
debug.setLevel( [ level ] ) | - |
level | (Number) If 0, disables logging. If negative, shows N lowest priority levels of log messages. If positive, shows N highest priority levels of log messages. |
log (1) < debug (2) < info (3) < warn (4) < error (5)
Set a callback to be used if logging isn’t possible due to console.log not existing. If unlogged logs exist when callback is set, they will all be logged immediately unless a limit is specified.
debug.setCallback( callback [, force ] [, limit ] )
callback | (Function) The aforementioned callback function. The first argument is the logging level, and all subsequent arguments are those passed to the initial debug logging method. |
force | (Boolean) If false, log to console.log if available, otherwise callback. If true, log to both console.log and callback. |
limit | (Number) If specified, number of lines to limit initial scrollback to. |