src/logger.js   A
last analyzed

Complexity

Total Complexity 1
Complexity/F 1

Size

Lines of Code 42
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 27
dl 0
loc 42
rs 10
c 0
b 0
f 0
wmc 1
mnd 0
bc 0
fnc 1
bpm 0
cpm 1
noi 0
1
import { Decorator } from 'logger-decorator';
2
import { createLogger, format, transports } from 'winston';
3
import { name } from '../package';
4
5
/* eslint-disable camelcase */
6
const { npm_config_loglevel, DEBUG, LOG_LEVEL } = process.env;
7
/* istanbul ignore next */
8
const level = LOG_LEVEL || DEBUG && 'debug' || npm_config_loglevel || 'info';
9
/* eslint-enable camelcase*/
10
11
const appNameFormat = format(info => {
12
    info.application = name; // eslint-disable-line no-param-reassign
13
14
    return info;
15
});
16
17
export const LogLeveles = {
18
    error   : 0,
19
    warn    : 1,
20
    info    : 2,
21
    notice  : 3,
22
    verbose : 4,
23
    debug   : 5
24
};
25
26
const logger = createLogger({
27
    level,
28
    levels : LogLeveles,
29
    format : format.combine(
30
        appNameFormat(),
31
        format.timestamp(),
32
        format.json()
33
    ),
34
    transports : [ new transports.Console() ]
35
});
36
37
export const logDecorator = new Decorator({
38
    logger : logger.log.bind(logger),
39
    level  : 'info'
40
});
41
42
export default logger;
43
44