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

lib/logger/Logger.js   A

Size

Lines of Code 107

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 6.54%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
nc 1
dl 0
loc 107
rs 10
ccs 7
cts 107
cp 0.0654
noi 1

1 Function

Rating   Name   Duplication   Size   Complexity  
A Logger.js ➔ ??? 0 9 2
1
"use strict";
2
3 1
const wrapWinston = (winstonLogger, level, message, meta) => {
4
    const argList = [];
5
6 16
    argList.push(message);
7 16
    if (meta) {
8 16
        argList.push(meta);
9
    }
10 16
    winstonLogger[level].apply(winstonLogger, argList);
11
};
12
13
class Logger {
14
    /**
15
     *
16
     * @param {winston.Logger} logger
17
     */
18
    constructor(logger) {
19
        this.logger = logger;
20
    }
21
22
    /**
23
     * @public
24
     *
25
     * @param {string} message
26
     * @param {Object} meta
27
     */
28
    debug(message, meta = {}) {
29
        this.log('debug', message, meta);
30
    };
31
32
    /**
33
     * @public
34
     *
35
     * @param {string} message
36
     * @param {Object} meta
37
     */
38
    info(message, meta = {}) {
39
        this.log('info', message, meta);
40
    };
41
42
    /**
43
     * @public
44
     *
45
     * @param {string} message
46
     * @param {Object} meta
47
     */
48
    warning(message, meta = {}) {
49
        this.log('warn', message, meta);
50
    };
51
52
    /**
53
     * @public
54
     *
55
     * @param {string} message
56
     * @param {Object} meta
57
     */
58
    error(message, meta = {}) {
59
        this.log('error', message, meta);
60
    };
61
62
    /**
63
     * @protected
64
     * Could be overridden by child class
65
     *
66
     * @param {string} message
67
     * @param {Object} meta
68
     *
69
     * @returns {string}
70
     */
71
    normalizeMessage(message, meta = {}) {
0 ignored issues
show
Unused Code introduced by
The parameter meta is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
72
        return message;
73
    }
74
75
    /**
76
     * @protected
77
     * Could be overridden by child class
78
     *
79
     * @param {Object} meta
80
     *
81
     * @returns {Object}
82
     */
83
    normalizeMeta(meta = {}) {
84
        return meta;
85
    }
86
87
    /**
88
     * @protected
89
     *
90
     * @param {string} level
91
     * @param {string} message
92
     * @param {Object} meta
93
     */
94
    log(level, message, meta = {}) {
95
        meta = this.normalizeMeta(meta);
96
97 16
        return wrapWinston(
98
            this.logger,
99
            level,
100
            this.normalizeMessage(message, meta),
101
            meta
102
        );
103
    }
104
}
105
106
107
module.exports = Logger;
108