-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlog.js
More file actions
39 lines (33 loc) · 864 Bytes
/
log.js
File metadata and controls
39 lines (33 loc) · 864 Bytes
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
import app_config from "./app_config.js"
import winston from "winston"
let {createLogger, format, transports} = winston
const myFormat = format.printf((info) => {
const { level, message, label, timestamp, metadata } = info;
const rest = JSON.stringify(metadata);
if (rest != '{}')
return `${timestamp}: [${level}] ${message} ${rest}`;
else
return `${timestamp}: [${level}] ${message}`;
});
const logger = createLogger({
level: app_config.log_level,
format: format.combine(
format.metadata(),
format.splat(),
format.timestamp(),
myFormat,
),
defaultMeta : {},
transports: [
new transports.File({ filename: 'error.log', level: 'error' }),
new transports.File({ filename: 'combined.log' })
]
});
logger.add(new transports.Console({
defaultMeta : {},
format: format.combine(
format.cli(),
myFormat,
),
}));
export default logger