const getSimpleText = text => { return text.toString().toLowerCase(); }; const getCurrentDateTime = () => new Date().toISOString(); const loggerWithTimeStamp = text => getCurrentDateTime() + ': ' + getSimpleText(text); const loggerWithTimeStampAndLevel = (text, level) => ` [ ${level.toUpperCase()} ] ${loggerWithTimeStamp(text)}`; const loggerWithTimeStampAndLevelAndCallee = (text, level, callee) => { return 'Task: ' + callee + loggerWithTimeStampAndLevel(text, level); }; const log = function(text, level) { if (level) { console[level]( loggerWithTimeStampAndLevelAndCallee(text, level, log.caller.name) ); } else { console.info( loggerWithTimeStampAndLevelAndCallee(text, 'info', log.caller.name) ); } }; (function run() { log('This is logger statement'); log(Buffer.from('Something to log'), 'warn'); log('This is logger statement', 'error'); log('This is logger statement', 'error'); log('This is logger statement', 'error'); })();
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter