Update version to 0.0.16, add Appender and AppenderFactory classes, refactor LoggerFactory methods, and implement logging functionality with tests.

This commit is contained in:
2025-10-04 09:20:27 -04:00
parent ea8fd991a0
commit 07485bd0c3
14 changed files with 789 additions and 15 deletions

66
tests/Threshold.test.ts Normal file
View File

@@ -0,0 +1,66 @@
import { describe, it, expect } from 'bun:test';
import Threshold from '../src/level/Threshold';
import { LoggingLevel } from '../src/level/LoggingLevel';
import Defaults from '../src/Defaults';
describe('Threshold', () => {
describe('constructor', () => {
it('should use provided logging level', () => {
const threshold = new Threshold(LoggingLevel.Debug);
expect(threshold.value).toBe(LoggingLevel.Debug);
});
it('should use default logging level when none provided', () => {
const threshold = new Threshold();
expect(threshold.value).toBe(Defaults.loggingLevel);
});
});
describe('value getter/setter', () => {
it('should get and set threshold value', () => {
const threshold = new Threshold(LoggingLevel.Info);
expect(threshold.value).toBe(LoggingLevel.Info);
threshold.value = LoggingLevel.Debug;
expect(threshold.value).toBe(LoggingLevel.Debug);
threshold.value = LoggingLevel.Error;
expect(threshold.value).toBe(LoggingLevel.Error);
});
});
describe('threshold comparison logic', () => {
it('should work correctly for different levels', () => {
const threshold = new Threshold(LoggingLevel.Info);
// Info level (30) should allow Info (30), Warn (50), Error (60) but not Debug (10)
expect(threshold.value > LoggingLevel.Info).toBe(false); // 30 > 30 = false, so Info logs
expect(threshold.value > LoggingLevel.Warn).toBe(false); // 30 > 50 = false, so Warn logs
expect(threshold.value > LoggingLevel.Error).toBe(false); // 30 > 60 = false, so Error logs
expect(threshold.value > LoggingLevel.Debug).toBe(true); // 30 > 10 = true, so Debug doesn't log
});
it('should work with Debug threshold', () => {
const threshold = new Threshold(LoggingLevel.Debug);
// Debug level (10) should allow all levels
expect(threshold.value > LoggingLevel.Debug).toBe(false); // 10 > 10 = false
expect(threshold.value > LoggingLevel.Info).toBe(false); // 10 > 30 = false
expect(threshold.value > LoggingLevel.Warn).toBe(false); // 10 > 50 = false
expect(threshold.value > LoggingLevel.Error).toBe(false); // 10 > 60 = false
});
it('should work with Error threshold', () => {
const threshold = new Threshold(LoggingLevel.Error);
// Error level (60) should only allow Error and above
expect(threshold.value > LoggingLevel.Error).toBe(false); // 60 > 60 = false, so Error logs
expect(threshold.value > LoggingLevel.Warn).toBe(true); // 60 > 50 = true, so Warn doesn't log
expect(threshold.value > LoggingLevel.Info).toBe(true); // 60 > 30 = true, so Info doesn't log
expect(threshold.value > LoggingLevel.Debug).toBe(true); // 60 > 10 = true, so Debug doesn't log
});
});
});