-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlogger.js
32 lines (24 loc) · 861 Bytes
/
logger.js
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
const { createLogger, transports, format } = require("winston")
const LokiTransport = require("winston-loki")
const { LOKI_URL } = process.env
const consoleTransport = new transports.Console({
format: format.combine(format.simple(), format.colorize()),
})
// By default, only log to console
const loggerOptions = { transports: [consoleTransport] }
// If the Loki URL is provided, then also log to Loki
if (LOKI_URL) {
console.log(`[Logger] LOKI_URL provided: ${LOKI_URL}`)
const lokiTransport = new LokiTransport({
host: LOKI_URL,
labels: { app: "Shinsei manager" },
json: true,
format: format.json(),
replaceTimestamp: true,
onConnectionError: (err) => console.error(err),
})
loggerOptions.transports.push(lokiTransport)
}
const logger = createLogger(loggerOptions)
exports.loki_url = LOKI_URL
exports.logger = logger