Last active
November 27, 2018 14:16
-
-
Save fmalk/50cc59335a6cd4900599f101e770fe8b to your computer and use it in GitHub Desktop.
Simple Console Logger - better suited for AWS CloudWatch
This file contains 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
/* eslint-disable no-console */ | |
function notJson(test) { | |
return (test !== Object(test) || test instanceof Error); | |
} | |
function log(fn, ...args) { | |
fn(...args.map(x => (notJson(x) ? x : JSON.stringify(x)))); | |
} | |
const logger = { | |
trace: (...args) => { log(console.log, 'TRACE', ...args); }, | |
debug: (...args) => { log(console.log, 'DEBUG', ...args); }, | |
log: (...args) => { log(console.log, 'INFO', ...args); }, | |
info: (...args) => { log(console.log, 'INFO', ...args); }, | |
warn: (...args) => { log(console.error, 'WARN', ...args); }, | |
error: (...args) => { log(console.error, 'ERROR', ...args); }, | |
fatal: (...args) => { log(console.error, 'FATAL', ...args); }, | |
setLevel: () => {}, | |
}; | |
module.exports = logger; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment