c7d618ad92
Validate / test (pull_request) Failing after 21s
Tests added: - log-service.test.ts: hierarchical logger creation and threshold propagation - logger.test.ts: threshold inheritance, message propagation, falsy threshold bug coverage (LogLevel.ALL = 0), deferred messages, Error handling - log-message.test.ts: parseLogLevel parsing, flattenMessage object/string modes - console-log-appender.test.ts: threshold, formatter, all-level routing - buffer-log-appender.test.ts: buffer append, threshold filtering, clearBuffer - api-log-appender.test.ts: configuration defaults, threshold, auth token Also fixes src/index.ts to export BufferLogAppender which was previously missing from the barrel export.
55 lines
1.5 KiB
TypeScript
55 lines
1.5 KiB
TypeScript
import { describe, test, expect } from "bun:test";
|
|
import { LogService, LogLevel } from "../src";
|
|
|
|
describe("LogService", () => {
|
|
test("creates a root logger on construction", () => {
|
|
const svc = new LogService();
|
|
|
|
expect(svc.ROOT_LOGGER).toBeDefined();
|
|
expect(svc.ROOT_LOGGER.name).toBe("ROOT");
|
|
});
|
|
|
|
test("root logger defaults to ALL threshold", () => {
|
|
const svc = new LogService();
|
|
|
|
expect(svc.ROOT_LOGGER.threshold).toBe(LogLevel.ALL);
|
|
});
|
|
|
|
test("getLogger returns the same instance for the same name", () => {
|
|
const svc = new LogService();
|
|
|
|
const a = svc.getLogger("foo");
|
|
const b = svc.getLogger("foo");
|
|
|
|
expect(a).toBe(b);
|
|
});
|
|
|
|
test("getLogger creates hierarchical loggers", () => {
|
|
const svc = new LogService();
|
|
|
|
const foo = svc.getLogger("foo");
|
|
const fooBar = svc.getLogger("foo.bar");
|
|
const fooBarBaz = svc.getLogger("foo.bar.baz");
|
|
|
|
// foo.bar should be a child of foo
|
|
// We can verify by checking threshold propagation
|
|
foo.appenders = [{
|
|
threshold: LogLevel.ALL,
|
|
messages: [] as any[],
|
|
appendMessage(m: any) { this.messages!.push(m); },
|
|
}];
|
|
|
|
fooBar.info("propagate");
|
|
|
|
// The foo appender should receive the message from fooBar
|
|
expect(foo.appenders[0].messages.length).toBe(1);
|
|
});
|
|
|
|
test("getLogger allows setting threshold", () => {
|
|
const svc = new LogService();
|
|
|
|
const logger = svc.getLogger("with-threshold", LogLevel.ERROR);
|
|
expect(logger.threshold).toBe(LogLevel.ERROR);
|
|
});
|
|
});
|