Skip to content

Commit 850bcd0

Browse files
committed
Update logger implementation and remove old logger
Signed-off-by: Shubham Sharma <[email protected]>
1 parent cac152e commit 850bcd0

File tree

3 files changed

+18
-94
lines changed

3 files changed

+18
-94
lines changed

src/logger/ConsoleLogger.ts renamed to src/logger/ConsoleLoggerService.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,30 @@ limitations under the License.
1212
*/
1313

1414
/**
15-
* ConsoleLogger uses the in-built console module to log messages.
15+
* ConsoleLoggerService uses the in-built console module to log messages.
1616
*/
17-
class ConsoleLogger implements LoggerService {
17+
class ConsoleLoggerService implements LoggerService {
1818
error(message: any, ...optionalParams: any[]): void {
19-
console.error(message, ...optionalParams);
19+
console.error(`${this.getTime()} ERROR ${message}`, ...optionalParams);
2020
}
2121

2222
warn(message: any, ...optionalParams: any[]): void {
23-
console.warn(message, ...optionalParams);
23+
console.warn(`${this.getTime()} WARN ${message}`, ...optionalParams);
2424
}
2525

2626
info(message: any, ...optionalParams: any[]): void {
27-
console.info(message, ...optionalParams);
27+
console.info(`${this.getTime()} INFO ${message}`, ...optionalParams);
2828
}
2929

3030
verbose(message: any, ...optionalParams: any[]): void {
31-
console.log(message, ...optionalParams);
31+
console.log(`${this.getTime()} VERBOSE ${message}`, ...optionalParams);
3232
}
3333

3434
debug(message: any, ...optionalParams: any[]): void {
35-
console.debug(message, ...optionalParams);
35+
console.debug(`${this.getTime()} DEBUG ${message}`, ...optionalParams);
36+
}
37+
38+
private getTime(): string {
39+
return new Date().toISOString();
3640
}
3741
}

src/logger/Logger.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class Logger {
2222
* Creates a new instance of the Logger class.
2323
* If an options is missing, it falls back to the default values.
2424
* The default log level is 'info'.
25-
* The default log service is the ConsoleLogger.
25+
* The default log service is the ConsoleLoggerService.
2626
* @param options Logger options
2727
*/
2828
constructor(options?: LoggerOptions) {
@@ -35,37 +35,37 @@ export class Logger {
3535
if (options && options.logService) {
3636
this.logService = options.logService;
3737
} else {
38-
this.logService = new ConsoleLogger();
38+
this.logService = new ConsoleLoggerService();
3939
}
4040
}
4141

4242
error(component: string, area: string, message: any, ...optionalParams: any[]): void {
4343
if (this.logLevel >= LogLevel.error) {
44-
this.logService.error(`[${component}] ${area}: ${message}`, ...optionalParams);
44+
this.logService.error(`[${component}, ${area}] ${message}`, ...optionalParams);
4545
}
4646
}
4747

4848
warn(component: string, area: string, message: any, ...optionalParams: any[]): void {
4949
if (this.logLevel >= LogLevel.warn) {
50-
this.logService.warn(`[${component}] ${area}: ${message}`, ...optionalParams);
50+
this.logService.warn(`[${component}, ${area}] ${message}`, ...optionalParams);
5151
}
5252
}
5353

5454
info(component: string, area: string, message: any, ...optionalParams: any[]): void {
5555
if (this.logLevel >= LogLevel.info) {
56-
this.logService.info(`[${component}] ${area}: ${message}`, ...optionalParams);
56+
this.logService.info(`[${component}, ${area}] ${message}`, ...optionalParams);
5757
}
5858
}
5959

6060
verbose(component: string, area: string, message: any, ...optionalParams: any[]): void {
6161
if (this.logLevel >= LogLevel.verbose) {
62-
this.logService.verbose(`[${component}] ${area}: ${message}`, ...optionalParams);
62+
this.logService.verbose(`[${component}, ${area}] ${message}`, ...optionalParams);
6363
}
6464
}
6565

6666
debug(component: string, area: string, message: any, ...optionalParams: any[]): void {
6767
if (this.logLevel >= LogLevel.debug) {
68-
this.logService.debug(`[${component}] ${area}: ${message}`, ...optionalParams);
68+
this.logService.debug(`[${component}, ${area}]: ${message}`, ...optionalParams);
6969
}
7070
}
7171
}

src/utils/Logger.util.ts

Lines changed: 0 additions & 80 deletions
This file was deleted.

0 commit comments

Comments
 (0)