aboutsummaryrefslogtreecommitdiff
path: root/src/util/logger.ts
blob: d779718586998cf2ebcac9a323481683e472e550 (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
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";

const consoleFormat = combine(
  colorize(),
  printf(({ level, message, label, timestamp }) => {
    return `${timestamp} [${label}] ${level}: ${message}`;
  })
);

/**
 * 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 })),
  transports: [new Console({ level: level, format: consoleFormat })],
});