Cross-Browser console.log() Wrapper
Safe, clear console logging for every browser
Just drop consolelog.js in your project and start passing data to
log(). Whichever browser you're testing in, you'll see your data in the console — if the browser doesn't have a console, Firebug Lite will load. You can pass any variable type: strings, objects, arrays, functions, etc.
npm install consolelog
bower install consolelog
Or just download consolelog.js and reference it in your page with a
log() wherever you want to write to the console.
Consolelog.js is AMD-compliant and supports Common JS:
You can change some optional preferences by passing an object to
log.settings(). The defaults are shown below.
logsettingslineNumber: truegroup:label: 'Log:'collapsed: false;
- Whether to append the actual line number to each log. Not supported by all browsers.
group(Boolean or object)
- Groups the arguments for each log together
collapsed: truewill collapse each group (in browsers that support collapsing)
label: "some string"sets the label or name for the groups
- Simply setting
group: trueis a shorthand way of selecting the defaults
Firebug, WebKit's Developer Tools, and Opera's Dragonfly print useful, interactive items to the console. For example:
console.log"Here's a string"3.14"alpha": 5 "bravo": falsedocumentgetElementById'charlie';
Some browsers that have a primitive console — ones that does not expand arrays, links DOM elements to the source code, prints objects as
[object Object] rather than listing their properties, etc.
Some cannot accept multiple arguments to a single
console.log call. This includes IE 7/8/9/10, iOS 5 and older, and Opera 11 and older, among others.
detailPrint companion plugin, special objects are presented in a more readable manner.
Console.log-wrapper is released under three licenses: MIT, BSD, and GPL.