# Code coverage report for node-ssdp/lib/logger.js

## Statements: 48.15% (13 / 27) Branches: 41.67% (5 / 12) Functions: 25% (1 / 4) Lines: 50% (13 / 26) Ignored: none

All files » node-ssdp/lib/ » logger.js

    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
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67

    1
    1
    1

    1

    1
    17

    17

    17

    17

    17

    17

    17

    17

     /**
     * Use logging facilities when available
     * and stub it out when not.
     */

    try {
      var bunyan = require('bunyan')
      var PrettyStream = require('bunyan-prettystream')

      process.stdout.setMaxListeners(100)
    } catch(e) {
      module.exports = function () {
        var stubs = {};

        ['trace', 'debug', 'info', 'warn', 'error', 'fatal'].forEach(function (level) {
          stubs[level] = function () {}
        })

        return stubs
      }

      return
    }

    module.exports = function(config) {
      Iif (!config) config = {}

      var loggerConfig = {
        name: config.logger_name,
        streams: [],
        src: false
      }

      Iif (config.logLevel) {
        if (config.logJSON) {
          loggerConfig.streams.push({
            level: 'error',
            stream: process.stdout
          })
        } else {
          var prettyStdOut = new PrettyStream()
          prettyStdOut.pipe(process.stdout)

          loggerConfig.streams.push({
            level: 'error',
              stream: prettyStdOut,
              type: 'raw'
          })
        }
      }

      var logger = bunyan.createLogger(loggerConfig)

      Iif (process.env.LOG_LEVEL) {
        logger.level(process.env.LOG_LEVEL)
      } else {
      config.logLevel && logger.level(config.logLevel)
      }

      // enable call source location in the log
      Iif (logger.level() <= 20) {
        logger.src = true
      }

      return logger
    }