Skip to content

Commit

Permalink
fix(winston): verify the length of winston transports
Browse files Browse the repository at this point in the history
  • Loading branch information
realyuyanan authored and mapleeit committed Aug 10, 2021
1 parent 44d0327 commit 6976a6e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
5 changes: 5 additions & 0 deletions lib/core/__test__/winston.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 2 additions & 3 deletions lib/core/winston.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Transports> = 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
Expand Down
2 changes: 1 addition & 1 deletion typings/type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ declare namespace NodeJS {
interface Global {
tswConfig: {
plugins: any[];
winstonTransports: any[];
winstonTransports?: any[];
cleanLog?: boolean;
logLevel?: "DEBUG" | "INFO" | "WARN" | "ERROR";
};
Expand Down

0 comments on commit 6976a6e

Please sign in to comment.