Add logging framework with Logger, LoggerFactory, and appenders

- Introduced ILogger interface for logging methods
- Implemented Logger class with various logging levels and message formatting
- Created LoggerFactory for managing logger instances and appender configuration
- Added LoggingLevel enum and mapping for logging level types
- Developed ConsoleAppender and TechnikerMeAppender for different logging outputs
- Implemented appender management with AppenderFactory and base Appender class
- Established Threshold class for controlling logging levels
This commit is contained in:
2025-10-30 03:15:16 -04:00
parent cb34256276
commit 1587ed7428
12 changed files with 407 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
import {LoggingLevel, type LoggingLevelType} from '../LoggingLevel';
import LoggingLevelMapping from '../LoggingLevelMapping';
import type {IAppender} from './IAppender';
import {assertUnreachable} from '@techniker-me/tools';
export default class ConsoleAppender implements IAppender {
public log(timestamp: string, level: LoggingLevelType, category: string, message: string) {
const loggingLevel = LoggingLevelMapping.convertLoggingLevelTypeToLoggingLevel(level);
switch (loggingLevel) {
case LoggingLevel.Off:
break;
case LoggingLevel.Warn:
case LoggingLevel.Error:
console.error(`${timestamp} [${level}] [${category}] ${message}`);
break;
case LoggingLevel.Info:
case LoggingLevel.Debug:
case LoggingLevel.Trace:
case LoggingLevel.Silly:
case LoggingLevel.All:
console.log(`${timestamp} [${level}] [${category}] ${message}`);
break;
default:
assertUnreachable(loggingLevel);
}
}
}