All files / src Logger.ts

65.51% Statements 19/29
100% Branches 3/3
66.66% Functions 2/3
65.51% Lines 19/29

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 34 35 36 37 38 391x     1x 1x 1x 1x 1x 1x 1x 1x 1x       1x 16x 16x       1x                       1x 3x 3x 3x 3x  
import winston from "winston";
import { Env } from "@/Env";
 
const logLevelStrings = [
  "error",
  "warn",
  "info",
  "http",
  "verbose",
  "debug",
  "silly",
] as const;
 
export type LogLevelString = (typeof logLevelStrings)[number];
 
export function isLogLevelString(s: string): s is LogLevelString {
  return logLevelStrings.some((v) => v === s);
}
 
export type Logger = winston.Logger;
 
export function createLogger(env: Env, options: object): Logger {
  return winston.createLogger({
    level: env.logLevel,
    defaultMeta: { name: env.appName, ...options },
    format: winston.format.combine(
      winston.format.colorize(),
      winston.format.simple()
    ),
    transports: [new winston.transports.Console()],
  });
}
 
export function createNopLogger(): Logger {
  return winston.createLogger({
    silent: true,
  });
}