lib/logger/index.js   A
last analyzed

Complexity

Total Complexity 6
Complexity/F 6

Size

Lines of Code 43
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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

1 Function

Rating   Name   Duplication   Size   Complexity  
A index.js ➔ ??? 0 10 4
1
"use strict";
2
3
const winston = require('winston');
4
const config = require('config');
5
const path = require('path');
6
const moment = require('moment');
7
const Logger = require('./Logger');
8
9
const loggerConfig = config.logger;
10
11
const format = (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
 * @type {Logger} Default logger for the app. Use console output and a log file
24
 */
25
module.exports = new Logger(new winston.Logger({
26
    transports: [
27
        new winston.transports.Console({
28
            level: config.debug === true ? 'debug' : loggerConfig.level,
29
            name: 'console',
30
            json: false,
31
            colorize: true
32
        }),
33
        new  winston.transports.File({
34
            name: 'default',
35
            level: config.debug === true ? 'debug' : loggerConfig.level,
36
            filename: path.resolve(loggerConfig.path, './server.log'),
37
            maxsize: 1024,
38
            maxFiles: 4,
39
            json: false,
40
            formatter: format
41
        })
42
    ]
43
}));
44