Skip to content

Commit

Permalink
fix: adjust implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
sean-perkins committed Nov 13, 2024
1 parent f8f274b commit f05ecc3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
5 changes: 2 additions & 3 deletions core/src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
4 changes: 2 additions & 2 deletions core/src/utils/logging/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};
Expand All @@ -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);
}
};
Expand Down
16 changes: 8 additions & 8 deletions core/src/utils/logging/test/logging.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,23 @@ 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');

expect(consoleWarnSpy).toHaveBeenCalledWith('[Ionic Warn]: This is a warning message');
});
});

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();
});
});

Expand Down Expand Up @@ -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');
});
});

Expand Down

0 comments on commit f05ecc3

Please sign in to comment.