Failed Conditions
Push — master ( f5e7b3...711045 )
by Yo
01:30
created

lib/logger/Logger.js   A

Size

Lines of Code 101

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
nc 1
dl 0
loc 101
rs 10
noi 1

1 Function

Rating   Name   Duplication   Size   Complexity  
A Logger.js ➔ ??? 0 9 2
1
"use strict";
2
3
const wrapWinston = (winstonLogger, level, message, meta) => {
4
    const argList = [];
5
6
    argList.push(message);
7
    if (meta = {}) {
8
        argList.push(meta);
9
    }
10
    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
    starting(taskName) {
23
        this.info(`Starting ${taskName} ...`);
24
    }
25
26
    started(taskName) {
27
        this.info(`${taskName} started`);
28
    }
29
30
    /**
31
     * @public
32
     *
33
     * @param {string} message
34
     * @param {Object} meta
35
     */
36
    debug(message, meta = {}) {
37
        this.log('debug', message, meta);
38
    };
39
40
    /**
41
     * @public
42
     *
43
     * @param {string} message
44
     * @param {Object} meta
45
     */
46
    info(message, meta = {}) {
47
        this.log('info', message, meta);
48
    };
49
50
    /**
51
     * @public
52
     *
53
     * @param {string} message
54
     * @param {Object} meta
55
     */
56
    warning(message, meta = {}) {
57
        this.log('warn', message, meta);
58
    };
59
60
    /**
61
     * @public
62
     *
63
     * @param {string} message
64
     * @param {Object} meta
65
     */
66
    error(message, meta = {}) {
67
        this.log('error', message, meta);
68
    };
69
70
    /**
71
     * @protected
72
     * Could be overridden by child class
73
     *
74
     * @param {string} message
75
     * @param {Object} meta
76
     *
77
     * @returns {string}
78
     */
79
    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...
80
        return message;
81
    }
82
83
    /**
84
     * @protected
85
     *
86
     * @param {string} level
87
     * @param {string} message
88
     * @param {Object} meta
89
     */
90
    log(level, message, meta = {}) {
91
        return wrapWinston(
92
            this.logger,
93
            level,
94
            this.normalizeMessage(message, meta),
95
            meta
96
        );
97
    }
98
}
99
100
101
module.exports = Logger;
102