Skip to content

Instantly share code, notes, and snippets.

@codeinthehole
Created May 15, 2013 10:54
Show Gist options
  • Select an option

  • Save codeinthehole/5583150 to your computer and use it in GitHub Desktop.

Select an option

Save codeinthehole/5583150 to your computer and use it in GitHub Desktop.
A Javascript logger which has a similar API to Python's logging module
var logger = (function(console){
var log = console.log.bind(console) || function(){};
var obj = {
info: (console.info) ? console.info.bind(console) : log,
error: (console.error) ? console.error.bind(console) : log
};
if (console.warn) {
obj.warning = console.warn.bind(console);
} else if (console.warning) {
obj.warning = console.warning.bind(console);
}
return obj;
})(console || {});
// Usage:
logger.info("Something good happened");
logger.warning("Something bad happened");
logger.error("Something TERRIBLE happened");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment