-
Notifications
You must be signed in to change notification settings - Fork 1
/
logger.ts
35 lines (33 loc) · 1008 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
import { colors, log, logger, logLevels } from "./3p/std.ts";
import { format } from "./3p/date-fns.ts";
export type Logger = logger.Logger;
export type WithLogger = { logger: Logger };
export async function createLogger(level: logLevels.LevelName = "WARNING") {
const nextLevel = level.toUpperCase() as logLevels.LevelName;
await log.setup({
handlers: {
console: new log.handlers.ConsoleHandler(nextLevel, {
formatter: (info: logger.LogRecord) => {
return `${colors.blue("[rad]")} ${
format(
info.datetime,
"HH:mm:ss",
undefined,
)
} ${
info.levelName.length === 4 ? " " : ""
}(${info.levelName.toLowerCase()}) ${info.msg}`;
},
}),
},
loggers: {
rad: {
level: nextLevel,
handlers: ["console"],
},
},
});
const logger = log.getLogger("rad");
if (!logger) throw new Error("failed to find logger");
return logger;
}