Refactor logging level handling and remove example usage
* Updated `CommandLineOptions` and `ConfigurationObject` to use `LoggingLevel` type instead of string for log levels. * Modified `LoggerFactory` to set logging levels using the new `LoggingLevelMapping` methods. * Removed the `example-usage.ts` file as it was no longer needed. * Adjusted `Threshold` class to simplify logging level management.
This commit is contained in:
@@ -1,19 +1,19 @@
|
||||
import { ConsoleAppender } from './appenders/ConsoleAppender';
|
||||
import IAppender from './appenders/IAppender';
|
||||
import {Logger} from './Logger';
|
||||
import {LoggingLevel} from './LoggingLevel';
|
||||
import {LoggingLevel, LoggingLevelMapping, LoggingLevelType} from './LoggingLevel';
|
||||
import {Threshold} from './Threshold';
|
||||
|
||||
export default class LoggerFactory {
|
||||
private static readonly _loggerForCategory: Map<string, Logger> = new Map();
|
||||
private static readonly _threshold: Threshold = new Threshold({level: LoggingLevel.Debug});
|
||||
private static readonly _threshold: {level: LoggingLevel} = {level: LoggingLevel.Info};
|
||||
private static readonly _appenders: IAppender[] = [new ConsoleAppender()];
|
||||
|
||||
public static getLogger(category: string): Logger {
|
||||
let logger = LoggerFactory._loggerForCategory.get(category);
|
||||
|
||||
if (logger === undefined) {
|
||||
logger = new Logger({category, threshold: LoggerFactory._threshold, appenders: LoggerFactory._appenders});
|
||||
logger = new Logger({category, threshold: new Threshold(LoggerFactory._threshold), appenders: LoggerFactory._appenders});
|
||||
|
||||
LoggerFactory._loggerForCategory.set(category, logger);
|
||||
}
|
||||
@@ -21,6 +21,12 @@ export default class LoggerFactory {
|
||||
return logger;
|
||||
}
|
||||
|
||||
public static setLoggingLevel(level: LoggingLevelType): void {
|
||||
const loggingLevel = LoggingLevelMapping.convertLoggingLevelTypeToLoggingLevel(level);
|
||||
console.log(`${new Date().toISOString()} [LoggerFactory] Setting logging level to [${level}]`);
|
||||
LoggerFactory._threshold.level = loggingLevel;
|
||||
}
|
||||
|
||||
private constructor() {
|
||||
throw new Error('[LoggerFactory] is a static class that may not be instantiated');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user