Skip to content

Instantly share code, notes, and snippets.

@fmalk
Last active November 27, 2018 14:16
Show Gist options
  • Save fmalk/50cc59335a6cd4900599f101e770fe8b to your computer and use it in GitHub Desktop.
Save fmalk/50cc59335a6cd4900599f101e770fe8b to your computer and use it in GitHub Desktop.
Simple Console Logger - better suited for AWS CloudWatch
/* 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