-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.ts
39 lines (36 loc) · 899 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
30
31
32
33
34
35
36
37
38
39
import { log } from "./deps.ts";
async function configureLogger() {
return await log.setup({
handlers: {
console: new log.handlers.ConsoleHandler("DEBUG", {
formatter: "{datetime} {levelName} {msg}",
}),
file: new log.handlers.RotatingFileHandler("INFO", {
filename: "./bot.log",
maxBytes: 1000000,
maxBackupCount: 5,
formatter: (rec) =>
JSON.stringify({
region: rec.loggerName,
ts: rec.datetime,
level: rec.levelName,
data: rec.msg,
}),
}),
},
loggers: {
default: {
level: "DEBUG",
handlers: ["console"],
},
client: {
level: "INFO",
handlers: ["file"],
},
},
});
}
export async function getLogger(logger: string = "client") {
await configureLogger();
return log.getLogger(logger);
}