Skip to content

Commit e3c8acd

Browse files
committed
refactor(utils): update LogLevel to enum
1 parent 5c18c91 commit e3c8acd

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

core/src/utils/config.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { SpinnerTypes } from '../components/spinner/spinner-configs';
22
import type { TabButtonLayout } from '../components/tab-bar/tab-bar-interface';
33
import type { AnimationBuilder, Mode } from '../interface';
44

5+
import type { LogLevel } from './logging';
56
import type { PlatformConfig } from './platform';
67

78
export interface IonicConfig {
@@ -221,13 +222,13 @@ export interface IonicConfig {
221222
experimentalCloseWatcher?: boolean;
222223

223224
/**
224-
* Developers may configure the logging level for Ionic Framework.
225+
* Configures the logging level for Ionic Framework:
225226
*
226-
* - `OFF` will not log any errors or warnings.
227-
* - `WARN` will log all errors and warnings.
228-
* - `ERROR` will log only errors.
227+
* - `OFF`: No errors or warnings are logged.
228+
* - `WARN`: Logs errors and warnings.
229+
* - `ERROR`: Logs only errors.
229230
*/
230-
logLevel?: 'OFF' | 'ERROR' | 'WARN';
231+
logLevel?: LogLevel;
231232

232233
// PRIVATE configs
233234
keyboardHeight?: number;

core/src/utils/logging/index.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,34 @@
11
import { config } from '@global/config';
22

3+
export const enum LogLevel {
4+
INFO = 'INFO',
5+
ERROR = 'ERROR',
6+
WARN = 'WARN',
7+
}
8+
39
/**
410
* Logs a warning to the console with an Ionic prefix
511
* to indicate the library that is warning the developer.
612
*
713
* @param message - The string message to be logged to the console.
814
*/
915
export const printIonWarning = (message: string, ...params: any[]) => {
10-
const logLevel = config.get('logLevel', 'WARN');
11-
if (['WARN'].includes(logLevel)) {
16+
const logLevel = config.get('logLevel', LogLevel.WARN);
17+
if ([LogLevel.WARN].includes(logLevel)) {
1218
return console.warn(`[Ionic Warning]: ${message}`, ...params);
1319
}
1420
};
1521

16-
/*
22+
/**
1723
* Logs an error to the console with an Ionic prefix
1824
* to indicate the library that is warning the developer.
1925
*
2026
* @param message - The string message to be logged to the console.
2127
* @param params - Additional arguments to supply to the console.error.
2228
*/
2329
export const printIonError = (message: string, ...params: any[]) => {
24-
const logLevel = config.get('logLevel', 'ERROR');
25-
if (['ERROR', 'WARN'].includes(logLevel)) {
30+
const logLevel = config.get('logLevel', LogLevel.ERROR);
31+
if ([LogLevel.ERROR, LogLevel.WARN].includes(logLevel)) {
2632
return console.error(`[Ionic Error]: ${message}`, ...params);
2733
}
2834
};

0 commit comments

Comments
 (0)