UNPKG

2.04 kBJavaScriptView Raw
1var appRoot = require('app-root-path');
2var winston = require('winston');
3
4
5var options = {
6 file: {
7 level: 'info',
8 filename: `${appRoot}/logs/chat21.log`,
9 handleExceptions: true,
10 json: false,
11 maxsize: 5242880, // 5MB
12 maxFiles: 5,
13 colorize: false,
14 format: winston.format.simple()
15 },
16 console: {
17 level: 'info',
18 handleExceptions: true,
19 json: true,
20 colorize: true,
21 format: winston.format.simple()
22 },
23 };
24
25// https://stackoverflow.com/questions/51074805/typeerror-winston-logger-is-not-a-constructor-with-winston-and-morgan
26// var logger = new winston.Logger({
27// transports: [
28// new winston.transports.File(options.file),
29// new winston.transports.Console(options.console)
30// ],
31// exitOnError: false, // do not exit on handled exceptions
32// });
33
34
35
36
37
38// require('winston-mongodb');
39
40// if (process.env.NODE_ENV == 'test') {
41// var logsDb = config.databasetest;
42// }else {
43// var logsDb = config.database;
44// }
45
46 let logger = winston.createLogger({
47 transports: [
48 new (winston.transports.Console)(options.console),
49 // new (winston.transports.File)(options.errorFile),
50 new (winston.transports.File)(options.file),
51 // new (winston.transports.MongoDB)( {db: logsDb, collection: "logs"})
52 ],
53 exitOnError: false, // do not exit on handled exceptions
54 });
55
56 logger.stream = {
57 write: function(message, encoding) {
58 logger.info(message);
59 },
60 };
61
62 // if (process.env.NODE_ENV !== 'production') {
63 // logger.add(new winston.transports.Console({
64 // format: winston.format.simple()
65 // }));
66 // }
67
68 /**
69 * Requiring `winston-mongodb` will expose
70 * `winston.transports.MongoDB`
71 */
72 // require('winston-mongodb');
73 // winston.add(winston.transports.MongoDB,
74 // {
75 // // db: config.databasetest,
76 // db: 'mongodb://localhost/tiledesk-test',
77 // collection: "logs"
78 // }
79 // );
80
81
82 module.exports = logger;