From f05ecc3df69d37d76f5ca87b0763a7cca1c63e7d Mon Sep 17 00:00:00 2001 From: Sean Perkins Date: Wed, 13 Nov 2024 14:06:23 -0500 Subject: [PATCH] fix: adjust implementation --- core/src/utils/config.ts | 5 ++--- core/src/utils/logging/index.ts | 4 ++-- core/src/utils/logging/test/logging.spec.ts | 16 ++++++++-------- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/core/src/utils/config.ts b/core/src/utils/config.ts index d95cd6a7241..4be29061dae 100644 --- a/core/src/utils/config.ts +++ b/core/src/utils/config.ts @@ -222,11 +222,10 @@ export interface IonicConfig { /** * Developers may configure the logging level for Ionic Framework. - * This will log all logs at the specified level and above. * - * - `OFF` will not log any logs. - * - `ERROR` will log all errors. + * - `OFF` will not log any errors or warnings. * - `WARN` will log all errors and warnings. + * - `ERROR` will log only errors. */ logLevel?: 'OFF' | 'ERROR' | 'WARN'; diff --git a/core/src/utils/logging/index.ts b/core/src/utils/logging/index.ts index 694cf7191f4..0ee2b59e14b 100644 --- a/core/src/utils/logging/index.ts +++ b/core/src/utils/logging/index.ts @@ -8,7 +8,7 @@ import { config } from '@global/config'; */ export const printIonWarning = (message: string, ...params: any[]) => { const logLevel = config.get('logLevel', 'WARN'); - if (['WARN', 'ERROR'].includes(logLevel)) { + if (['WARN'].includes(logLevel)) { return console.warn(`[Ionic Warn]: ${message}`, ...params); } }; @@ -22,7 +22,7 @@ export const printIonWarning = (message: string, ...params: any[]) => { */ export const printIonError = (message: string, ...params: any[]) => { const logLevel = config.get('logLevel', 'ERROR'); - if (['ERROR'].includes(logLevel)) { + if (['ERROR', 'WARN'].includes(logLevel)) { return console.error(`[Ionic Error]: ${message}`, ...params); } }; diff --git a/core/src/utils/logging/test/logging.spec.ts b/core/src/utils/logging/test/logging.spec.ts index e1825a77357..7f2f5b50292 100644 --- a/core/src/utils/logging/test/logging.spec.ts +++ b/core/src/utils/logging/test/logging.spec.ts @@ -26,9 +26,9 @@ describe('Logging', () => { }); }); - describe("when the logLevel configuration is set to 'ERROR'", () => { + describe("when the logLevel configuration is set to 'WARN'", () => { it('logs a warning to the console', () => { - config.set('logLevel', 'ERROR'); + config.set('logLevel', 'WARN'); printIonWarning('This is a warning message'); @@ -36,13 +36,13 @@ describe('Logging', () => { }); }); - describe("when the logLevel configuration is set to 'WARN'", () => { - it('logs a warning to the console', () => { - config.set('logLevel', 'WARN'); + describe("when the logLevel configuration is set to 'ERROR'", () => { + it('does not log a warning to the console', () => { + config.set('logLevel', 'ERROR'); printIonWarning('This is a warning message'); - expect(consoleWarnSpy).toHaveBeenCalledWith('[Ionic Warn]: This is a warning message'); + expect(consoleWarnSpy).not.toHaveBeenCalled(); }); }); @@ -91,12 +91,12 @@ describe('Logging', () => { }); describe("when the logLevel configuration is set to 'WARN'", () => { - it('does not log an error to the console', () => { + it('logs an error to the console', () => { config.set('logLevel', 'WARN'); printIonError('This is an error message'); - expect(consoleErrorSpy).not.toHaveBeenCalled(); + expect(consoleErrorSpy).toHaveBeenCalledWith('[Ionic Error]: This is an error message'); }); });