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