Created
September 21, 2018 15:01
-
-
Save brophdawg11/b58b78f2ec94e4de72b6b0ec11edbc06 to your computer and use it in GitHub Desktop.
Dead Simple LogLevel-driven Logging
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
const logLevel = process.env.LOG_LEVEL; | |
const noop = () => {}; | |
export default { | |
debug: | |
logLevel === 'debug' ? | |
console.debug.bind(console) : | |
noop, | |
info: | |
(logLevel === 'debug' || | |
logLevel === 'info') ? | |
console.info.bind(console) : | |
noop, | |
log: | |
(logLevel === 'debug' || | |
logLevel === 'info' || | |
logLevel === 'log') ? | |
console.log.bind(console) : | |
noop, | |
warn: | |
(logLevel === 'debug' || | |
logLevel === 'info' || | |
logLevel === 'log' || | |
logLevel === 'warn') ? | |
console.warn.bind(console) : | |
noop, | |
error: | |
(logLevel === 'debug' || | |
logLevel === 'info' || | |
logLevel === 'log' || | |
logLevel === 'warn' || | |
logLevel === 'error') ? | |
console.error.bind(console) : | |
noop, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment