Created
May 15, 2013 10:54
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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