All files log.js

100% Statements 11/11
100% Branches 8/8
100% Functions 2/2
100% Lines 11/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38      1x   1x 6x 6x   6x         6x 36x         36x 6x     36x     6x                    
/*eslint-env node */
'use strict'
 
const bunyan = require('bunyan')
 
module.exports = (modulePath, logName, logLevel) => {
  logName = logName || process.env.IM_LOG_NAME || 'Log name not set'
  logLevel = logLevel || process.env.IM_LOG_LEVEL || 'INFO'
 
  const logger = bunyan.createLogger({
    name: logName,
    level: logLevel
  })
 
  const executeLog = (level, msg, data) => {
    let dataToLog = {
      file : modulePath,
      logData : data
    }
 
    if (process.env['IM_LOG_VERSION']) {
      dataToLog['component-version'] = process.env['IM_LOG_VERSION']
    }
 
    logger[level](dataToLog, msg)
  }
 
  return {
    fatal: executeLog.bind(this, 'fatal'),
    error: executeLog.bind(this, 'error'),
    warn: executeLog.bind(this, 'warn'),
    info: executeLog.bind(this, 'info'),
    debug: executeLog.bind(this, 'debug'),
    trace: executeLog.bind(this, 'trace'),
    logger: logger
  }
}