Total Complexity | 10 |
Complexity/F | 5 |
Lines of Code | 54 |
Function Count | 2 |
Duplicated Lines | 0 |
Ratio | 0 % |
Coverage | 80% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | "use strict"; |
||
2 | |||
3 | 1 | const winston = require('winston'); |
|
4 | 1 | const config = require('config'); |
|
5 | 1 | const path = require('path'); |
|
6 | 1 | const moment = require('moment'); |
|
7 | |||
8 | 1 | const loggerConfig = config.logger; |
|
9 | |||
10 | 1 | const formatFile = options => { |
|
11 | return ' [' + options.level.toUpperCase() + ']' |
||
12 | + '[' + moment(new Date()).format('YYYY-MM-DD HH:mm:ss') + ']' |
||
13 | + (options.message ? ' ' + options.message : '') |
||
14 | + ( |
||
15 | options.meta && Object.keys(options.meta).length |
||
16 | ? ' ' + JSON.stringify(options.meta) |
||
17 | : '' |
||
18 | ) |
||
19 | ; |
||
20 | }; |
||
21 | |||
22 | 1 | const formatConsole = options => { |
|
23 | return winston.config.colorize(options.level) + ':' |
||
24 | + (options.message ? ' ' + options.message : '') |
||
25 | + ( |
||
26 | options.meta && Object.keys(options.meta).length |
||
27 | ? ' ' + winston.config.colorize('data', JSON.stringify(options.meta)) |
||
28 | : '' |
||
29 | ) |
||
30 | ; |
||
31 | }; |
||
32 | |||
33 | /** |
||
34 | * @type {winston.Logger} Default logger wrapper for the whole app. Use console output and a log file |
||
35 | */ |
||
36 | 1 | module.exports = new winston.Logger({ |
|
37 | transports: [ |
||
38 | new winston.transports.Console({ |
||
39 | level: config.debug === true ? 'debug' : loggerConfig.level, |
||
40 | name: 'console', |
||
41 | json: false, |
||
42 | colorize: true, |
||
43 | formatter: formatConsole |
||
44 | }), |
||
45 | new winston.transports.File({ |
||
46 | name: 'default', |
||
47 | level: config.debug === true ? 'debug' : loggerConfig.level, |
||
48 | filename: path.resolve(loggerConfig.path, './server.log'), |
||
49 | tailable: true, |
||
50 | json: false, |
||
51 | formatter: formatFile |
||
52 | }) |
||
53 | ] |
||
54 | }); |
||
55 |