-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
40 lines (32 loc) · 1023 Bytes
/
index.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
40
import { SyslogStream, ConsoleStream } from "./lib/streams";
import { LokeLogger } from "./lib/logger";
import { metricsMiddleware } from "./lib/metrics";
import { Registry } from "prom-client";
export { SyslogStream, ConsoleStream } from "./lib/streams";
export { LokeLogger, Logger } from "./lib/logger";
export { nullLogger } from "./lib/null";
export interface CreateLoggerOptions {
syslog?: boolean;
metricsRegistry?: Registry;
showDebug?: boolean;
systemdPrefix?: boolean;
}
const systemd = Boolean(process.env.JOURNAL_STREAM);
export function create({
syslog = false,
metricsRegistry,
showDebug,
systemdPrefix = systemd,
}: CreateLoggerOptions = {}): LokeLogger {
const streams: NodeJS.WritableStream[] = [
new ConsoleStream(undefined, undefined, systemdPrefix),
];
if (syslog) {
streams.push(new SyslogStream());
}
let logger = new LokeLogger({ showDebug, streams });
if (metricsRegistry) {
logger = metricsMiddleware(metricsRegistry)(logger);
}
return logger;
}