Test Failed
Pull Request — master (#2)
by Yo
01:40
created

lib/logger/wrapper.js   A

Complexity

Total Complexity 10
Complexity/F 5

Size

Lines of Code 55
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 16.36%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
nc 4
dl 0
loc 55
rs 10
ccs 9
cts 55
cp 0.1636
crap 4.3404
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 1
const Logger = require('./Logger');
8
9 1
const loggerConfig = config.logger;
10
11 1
const formatFile = (options) => {
12
    return ' [' + options.level.toUpperCase() + ']'
13
        + '[' + moment(new Date()).format('YYYY-MM-DD HH:mm:ss') + ']'
14
        + (options.message ? ' ' + options.message : '')
15
        + (
16
            options.meta && Object.keys(options.meta).length
17
                ? ' ' + JSON.stringify(options.meta)
18
                : ''
19
        )
20
    ;
21
};
22
23 1
const formatConsole = (options) => {
24
    return winston.config.colorize(options.level) + ':'
25
        + (options.message ? ' ' + options.message : '')
26
        + (
27
            options.meta && Object.keys(options.meta).length
28
                ? ' ' + winston.config.colorize('data', JSON.stringify(options.meta))
29
                : ''
30
        )
31
    ;
32
};
33
34
/**
35
 * @type {winston.Logger} Default logger wrapper for the whole app. Use console output and a log file
36
 */
37 1
module.exports = new winston.Logger({
38
    transports: [
39
        new winston.transports.Console({
40
            level: config.debug === true ? 'debug' : loggerConfig.level,
41
            name: 'console',
42
            json: false,
43
            colorize: true,
44
            formatter: formatConsole
45
        }),
46
        new  winston.transports.File({
47
            name: 'default',
48
            level: config.debug === true ? 'debug' : loggerConfig.level,
49
            filename: path.resolve(loggerConfig.path, './server.log'),
50
            tailable: true,
51
            json: false,
52
            formatter: formatFile
53
        })
54
    ]
55
});
56