aboutsummaryrefslogtreecommitdiff
path: root/src/util/logger.ts
blob: d108ae072ed2a8d70ce21d0565e1e9fffc61de1b (plain) (blame)
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
import winston from "winston";
import { Format } from "logform";
import * as Transport from "winston-transport";
const { combine, splat, timestamp, label, colorize, printf } = winston.format;
const { Console } = winston.transports;

const LOG_LEVEL = process.env.LOG_LEVEL || "info";

/**
 * Provides standard logging format and output for the server.
 */
export default (
  clazz: string,
  level: string = LOG_LEVEL
): {
  format: Format;
  transports: Transport[];
} => ({
  format: combine(
    splat(),
    timestamp(),
    label({ label: clazz }),
    colorize(),
    printf(({ level, message, label, timestamp }) => {
      return `${timestamp} [${label}] ${level}: ${message}`;
    })
  ),
  transports: [new Console({ level: level })]
});