config/logger.js   A
last analyzed

Complexity

Total Complexity 4
Complexity/F 4

Size

Lines of Code 37
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 3
c 2
b 0
f 0
nc 4
dl 0
loc 37
rs 10
wmc 4
mnd 1
bc 3
fnc 1
bpm 3
cpm 4
noi 1

1 Function

Rating   Name   Duplication   Size   Complexity  
A logger.js ➔ ??? 0 1 1
1
var winston = require('winston')
2
var config = require('./')
3
var env = config.env
4
5
const tsFormat = () => '[' + (new Date()).toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, '$1') + ']'
6
7
switch (env) {
0 ignored issues
show
Coding Style introduced by
As per coding-style, switch statements should have a default case.
Loading history...
8
  case 'development': {
9
    winston.remove(winston.transports.Console)
10
    winston.add(winston.transports.Console, {
11
      level: config.logLevel,
12
      prettyPrint: true,
13
      colorize: 'all',
14
      timestamp: tsFormat,
15
      humanReadableUnhandledException: true
16
    })
17
    break
18
  }
19
20
  case 'production': {
21
    winston.remove(winston.transports.Console)
22
    winston.add(winston.transports.File, {
23
      filename: 'app.log',
24
      level: config.logLevel
25
    })
26
    break
27
  }
28
29
  case 'test': {
30
    winston.remove(winston.transports.Console)
31
    break
32
  }
33
}
34
35
winston.info('ENV=', env)
36
37
module.exports = winston
38