diff --git a/lib/core/__test__/winston.test.ts b/lib/core/__test__/winston.test.ts index 7039e90a..36ab959c 100644 --- a/lib/core/__test__/winston.test.ts +++ b/lib/core/__test__/winston.test.ts @@ -17,6 +17,11 @@ describe("test winstonHack env", () => { expect(logger.winstonLogger).toBe(undefined); }); + test("test winstonHack while the length of winstonTransports is 0", () => { + winstonHack(); + expect(logger.winstonLogger).toBe(undefined); + }); + test("test winstonHack while config with Console Transports ", () => { global.tswConfig.winstonTransports = [ new winston.transports.Console() diff --git a/lib/core/winston.ts b/lib/core/winston.ts index 14827586..f1fe7cdf 100644 --- a/lib/core/winston.ts +++ b/lib/core/winston.ts @@ -7,12 +7,11 @@ */ import * as winston from "winston"; -import * as Transports from "winston-transport"; import logger from "./logger/index"; export const winstonHack = (): void => { - const transports: Array = global.tswConfig.winstonTransports; - if (transports) { + const { winstonTransports: transports } = global.tswConfig; + if (Array.isArray(transports) && transports.length) { logger.winstonLogger = winston.createLogger({ format: winston.format.simple(), transports diff --git a/typings/type.d.ts b/typings/type.d.ts index fb78de7f..2677bc8c 100644 --- a/typings/type.d.ts +++ b/typings/type.d.ts @@ -26,7 +26,7 @@ declare namespace NodeJS { interface Global { tswConfig: { plugins: any[]; - winstonTransports: any[]; + winstonTransports?: any[]; cleanLog?: boolean; logLevel?: "DEBUG" | "INFO" | "WARN" | "ERROR"; };