-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlogging.js
More file actions
49 lines (46 loc) · 1.19 KB
/
logging.js
File metadata and controls
49 lines (46 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
* Logging for debugging and errors
*
* Last updated: 2023-July-11
* Author: Steven Smethurst
*
* Example use:
* ```js
* const loggerObj = require('./logging');
* const logger = loggerObj.child({ label: 'Example' });
* logger.error('An error message');
* logger.debug('An debug message');
* logger.info("An info message");
* ```
*/
const winston = require('winston');
var options = {
file: {
level: 'debug',
filename: './app.log',
handleExceptions: true,
maxsize: 5242880, // 5MB
maxFiles: 5,
colorize: false,
},
console: {
level: 'debug',
handleExceptions: true,
colorize: true,
}
};
var logger = winston.createLogger ({
transports: [
new winston.transports.File(options.file),
new winston.transports.Console(options.console),
],
exitOnError: false,
format: winston.format.combine(
winston.format.timestamp({
format: "MM-DD-YYYY HH:mm:ss",
}),
winston.format.align(),
winston.format.printf((message) => `${[message.timestamp]} ${message.label} ${message.level}: ${message.message}`)
),
});
module.exports = logger;