lib/logger/Logger.js   A
last analyzed

Size

Lines of Code 109

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 109
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
    stopping(taskName) {
27
        this.info(`Stopping ${taskName} ...`);
28
    }
29
30
    started(taskName) {
31
        this.info(`${taskName} started`);
32
    }
33
34
    stopped(taskName) {
35
        this.info(`${taskName} stopped`);
36
    }
37
38
    /**
39
     * @public
40
     *
41
     * @param {string} message
42
     * @param {Object} meta
43
     */
44
    debug(message, meta = {}) {
45
        this.log('debug', message, meta);
46
    };
47
48
    /**
49
     * @public
50
     *
51
     * @param {string} message
52
     * @param {Object} meta
53
     */
54
    info(message, meta = {}) {
55
        this.log('info', message, meta);
56
    };
57
58
    /**
59
     * @public
60
     *
61
     * @param {string} message
62
     * @param {Object} meta
63
     */
64
    warning(message, meta = {}) {
65
        this.log('warn', message, meta);
66
    };
67
68
    /**
69
     * @public
70
     *
71
     * @param {string} message
72
     * @param {Object} meta
73
     */
74
    error(message, meta = {}) {
75
        this.log('error', message, meta);
76
    };
77
78
    /**
79
     * @protected
80
     * Could be overridden by child class
81
     *
82
     * @param {string} message
83
     * @param {Object} meta
84
     *
85
     * @returns {string}
86
     */
87
    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...
88
        return message;
89
    }
90
91
    /**
92
     * @protected
93
     *
94
     * @param {string} level
95
     * @param {string} message
96
     * @param {Object} meta
97
     */
98
    log(level, message, meta = {}) {
99
        return wrapWinston(
100
            this.logger,
101
            level,
102
            this.normalizeMessage(message, meta),
103
            meta
104
        );
105
    }
106
}
107
108
109
module.exports = Logger;
110