-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlogger.ts
32 lines (24 loc) · 831 Bytes
/
logger.ts
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
import { createLogger, transports, format } from 'winston';
require('dotenv').config();
const { combine, label, timestamp, printf } = format;
const customFormat = printf(({ level, message, label, timestamp }) => {
return `${timestamp} [${label}] ${level}: ${message}`;
});
const createCustomLogger = (labelStr: string, level: string) =>
createLogger({
level: level || 'info', // Set the specified level or default to 'info'
format: combine(
label({ label: labelStr }),
timestamp(),
customFormat
),
transports: [
new transports.Console(),
new transports.File({
filename: process.env.LOG_FILE,
}),
],
});
const infoLogger = createCustomLogger('INFO', 'info');
const debugLogger = createCustomLogger('DEBUG', 'debug');
export { infoLogger, debugLogger };