-
Notifications
You must be signed in to change notification settings - Fork 927
Expand file tree
/
Copy pathlogger.ts
More file actions
35 lines (30 loc) · 951 Bytes
/
logger.ts
File metadata and controls
35 lines (30 loc) · 951 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
35
const { loadAndValidateEnv } = await import('./envConfig.js');
let LokiLogger: any;
try {
const { createLogger, transports, format } = await import('winston');
const LokiTransport = await import('winston-loki');
const envVars = loadAndValidateEnv();
LokiLogger = createLogger({
transports: [
...(envVars.LOKI_PUSH_ENABLED === 'true'
? [
new LokiTransport({
host: envVars.LOKI_HOST,
basicAuth: envVars.LOKI_AUTH,
labels: { app: envVars.SERVICE_NAME, env: envVars.NODE_ENV },
json: true,
format: format.json(),
replaceTimestamp: true,
onConnectionError: (err) => console.error(err),
}),
]
: []),
new transports.Console({
format: format.combine(format.simple(), format.colorize()),
}),
],
});
} catch (error) {
LokiLogger = null;
}
export { LokiLogger };