-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger.ts
More file actions
34 lines (29 loc) · 867 Bytes
/
logger.ts
File metadata and controls
34 lines (29 loc) · 867 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
import {
ConsoleStream,
every,
FileStream,
Logger,
TokenReplacer,
} from "./deps.ts";
// Small hack to not throw even if dir already exists
Deno.mkdirSync("./logs", { recursive: true });
export function createLogger(logfile: string) {
const c = new ConsoleStream()
.withMinLogLevel(20)
.withFormat(
new TokenReplacer()
.withDateTimeFormat("YYYY-MM-DD hh:mm:ss:SSS")
.withColor(true),
).withLogHeader(false);
const file = new FileStream(`./logs/${logfile}.log`)
.withMinLogLevel(30)
.withBufferSize(1024 * 4)
.withFormat(
new TokenReplacer()
.withDateTimeFormat("YYYY-MM-DD hh:mm:ss:SSS")
.withColor(false),
).withLogFileInitMode("append")
.withLogFileRotation(every(1).minutes()).withLogHeader(false);
file.setup();
return new Logger().addStream(file).addStream(c);
}