composition example

PHOTO EMBED

Tue Feb 09 2021 11:15:52 GMT+0000 (Coordinated Universal Time)

Saved by @noobj

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');
})();
content_copyCOPY