Created
March 14, 2017 03:12
-
-
Save jchip/5a4ef6efd20fbb6b011c39b4e17af763 to your computer and use it in GitHub Desktop.
makeSimpleLogger
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
function makeSimpleLogger() { | |
const levels = ["verbose", "info", "warn", "debug"]; | |
const tags = levels.reduce((a, l) => (a[l] = l.toUpperCase(), a), {}); | |
function log(tag, args) { | |
args = Array.prototype.concat.apply([`${tags[tag]}:`], args); | |
if (console[tag]) { | |
console[tag].apply(console, args); | |
} else { | |
console.log.apply(console, args); | |
} | |
} | |
return levels.reduce((a, l) => { | |
a[l] = function () { log(l, arguments) }; | |
return a; | |
}, {}); | |
} | |
const logger = makeSimpleLogger(); | |
logger.info("hello"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment