Failed Conditions
Push — master ( 2a10ca...dc3f81 )
by Yo
01:45
created

lib/logger/wrapper.js   A

Complexity

Total Complexity 10
Complexity/F 5

Size

Lines of Code 54
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 80%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
nc 4
dl 0
loc 54
ccs 8
cts 10
cp 0.8
crap 2.032
rs 10
wmc 10
mnd 1
bc 2
fnc 2
bpm 1
cpm 5
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A wrapper.js ➔ ??? 0 11 4
1
"use strict";
2
3 1
const winston = require('winston');
4 1
const config = require('config');
5 1
const path = require('path');
6 1
const moment = require('moment');
7
8 1
const loggerConfig = config.logger;
9
10 1
const formatFile = options => {
11
    return ' [' + options.level.toUpperCase() + ']'
12
        + '[' + moment(new Date()).format('YYYY-MM-DD HH:mm:ss') + ']'
13
        + (options.message ? ' ' + options.message : '')
14
        + (
15
            options.meta && Object.keys(options.meta).length
16
                ? ' ' + JSON.stringify(options.meta)
17
                : ''
18
        )
19
    ;
20
};
21
22 1
const formatConsole = options => {
23
    return winston.config.colorize(options.level) + ':'
24
        + (options.message ? ' ' + options.message : '')
25
        + (
26
            options.meta && Object.keys(options.meta).length
27
                ? ' ' + winston.config.colorize('data', JSON.stringify(options.meta))
28
                : ''
29
        )
30
    ;
31
};
32
33
/**
34
 * @type {winston.Logger} Default logger wrapper for the whole app. Use console output and a log file
35
 */
36 1
module.exports = new winston.Logger({
37
    transports: [
38
        new winston.transports.Console({
39
            level: config.debug === true ? 'debug' : loggerConfig.level,
40
            name: 'console',
41
            json: false,
42
            colorize: true,
43
            formatter: formatConsole
44
        }),
45
        new winston.transports.File({
46
            name: 'default',
47
            level: config.debug === true ? 'debug' : loggerConfig.level,
48
            filename: path.resolve(loggerConfig.path, './server.log'),
49
            tailable: true,
50
            json: false,
51
            formatter: formatFile
52
        })
53
    ]
54
});
55