aboutsummaryrefslogtreecommitdiff
path: root/src/util/logger.ts
blob: bafb829e5b27be110656d692f459165575a5c3de (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import winston from "winston";
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: combine(
    splat(),
    timestamp(),
    label({ label: clazz }),
    colorize(),
    printf(({ level, message, label, timestamp }) => {
      return `${timestamp} [${label}] ${level}: ${message}`;
    })
  ),
  transports: [new Console({ level: level })]
});