From 9b1026bac239bbad64c0e6ddd988df26dab3e636 Mon Sep 17 00:00:00 2001 From: Eugene Terehov Date: Thu, 13 Aug 2020 15:08:54 +0300 Subject: [PATCH 1/2] Fix Eslint --- src/LoggerHelper.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/LoggerHelper.ts b/src/LoggerHelper.ts index 66ea2f99..f5936506 100644 --- a/src/LoggerHelper.ts +++ b/src/LoggerHelper.ts @@ -106,7 +106,11 @@ export class LoggerHelper { public static overwriteConsole( $this: Logger, - handleLog: Function + handleLog: ( + logLevel: TLogLevelName, + logArguments: unknown[], + exposeStack?: boolean + ) => void ): ILogObject | void { ["log", "debug", "info", "warn", "trace", "error"].forEach( (name: string) => { From 4f98811f137f1c54ad2c0717e391b63afff9d3bc Mon Sep 17 00:00:00 2001 From: Eugene Terehov Date: Mon, 17 Aug 2020 11:46:48 +0300 Subject: [PATCH 2/2] Fix: #42: Transport should have own min log level / added test --- src/index.ts | 2 +- tests/transport.test.ts | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index d6d778de..c9cc8fbf 100644 --- a/src/index.ts +++ b/src/index.ts @@ -372,7 +372,7 @@ export class Logger { this._attachedTransports.forEach((transport: ITransportProvider) => { if ( logObject.logLevelId >= - Object.values(this._logLevels).indexOf(this.settings.minLevel) + Object.values(this._logLevels).indexOf(transport.minLevel) ) { transport.transportLogger[logLevel](logObject); } diff --git a/tests/transport.test.ts b/tests/transport.test.ts index 8fd71991..8ec46a29 100644 --- a/tests/transport.test.ts +++ b/tests/transport.test.ts @@ -67,4 +67,21 @@ describe("Logger: Transport", () => { doesLogContain(stdErr, transportErr[0].argumentsArray[0] as string) ).toBeTruthy(); }); + + test("different log level", (): void => { + logger.setSettings({ minLevel: "info" }); + + logger.silly("test message"); + logger.trace("test message"); + logger.debug("test message"); + logger.info("test message"); + logger.warn("test message"); + logger.error("test message"); + logger.fatal("test message"); + + // all 4: silly, trace, debug, info + expect(transportOut.length).toBe(4); + // info only to stdOut + expect(stdOut.length).toBe(1); + }); });