-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.ts
33 lines (25 loc) · 880 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
import { createLogger, transports, format } from "winston"
import LokiTransport from "winston-loki"
import dotenv from "dotenv"
dotenv.config()
export 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: "Coincheck scraper" },
json: true,
format: format.json(),
replaceTimestamp: true,
onConnectionError: (err: any) => console.error(err),
})
// @ts-ignore
loggerOptions.transports.push(lokiTransport)
}
export const logger = createLogger(loggerOptions)