From 50df6b4c37594cdbdf13e1f56ee7e519d99fb33d Mon Sep 17 00:00:00 2001 From: Tiara Rodney Date: Fri, 13 Mar 2026 22:55:17 +0100 Subject: [PATCH 1/3] feat(logger): add info, warning, error, and critical methods --- src/logger.ts | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/logger.ts b/src/logger.ts index 572f3a3..f43d18d 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -1,8 +1,11 @@ import { LogLevel, DEBUG, - NOTSET, + INFO, WARNING, + ERROR, + CRITICAL, + NOTSET, checkLevel, } from './log-level'; import { @@ -173,6 +176,34 @@ export class Logger extends Filterer { if (this.isEnabledFor(DEBUG)) { this._log(DEBUG, msg, options) } } + /** + * Log 'msg % args' with severity 'INFO' + */ + public info(msg: string, options?: LogOptions) { + if (this.isEnabledFor(INFO)) { this._log(INFO, msg, options) } + } + + /** + * Log 'msg % args' with severity 'WARNING' + */ + public warning(msg: string, options?: LogOptions) { + if (this.isEnabledFor(WARNING)) { this._log(WARNING, msg, options) } + } + + /** + * Log 'msg % args' with severity 'ERROR' + */ + public error(msg: string, options?: LogOptions) { + if (this.isEnabledFor(ERROR)) { this._log(ERROR, msg, options) } + } + + /** + * Log 'msg % args' with severity 'CRITICAL' + */ + public critical(msg: string, options?: LogOptions) { + if (this.isEnabledFor(CRITICAL)) { this._log(CRITICAL, msg, options) } + } + /** * A factory method which can be overriden in subclasses to create * specialized LogRecords. From d95c8d37da4370f6b7062491a2d829272760383f Mon Sep 17 00:00:00 2001 From: Tiara Rodney Date: Fri, 13 Mar 2026 22:56:01 +0100 Subject: [PATCH 2/3] test(logger): add tests for info, warning, error, and critical methods --- tests/unit/logger.test.ts | 64 ++++++++++++++++++++++++++++----------- 1 file changed, 46 insertions(+), 18 deletions(-) diff --git a/tests/unit/logger.test.ts b/tests/unit/logger.test.ts index c88e98a..db1eb75 100644 --- a/tests/unit/logger.test.ts +++ b/tests/unit/logger.test.ts @@ -124,32 +124,60 @@ describe('Logger', () => { }); }); - describe('debug', () => { - test('invokes handler when level is DEBUG', () => { - const logger = new Logger('test', DEBUG); - const emitted: LogRecord[] = []; + describe('level methods', () => { + let logger: Logger; + let emitted: LogRecord[]; - class TestHandler extends Handler { - emit(record: LogRecord) { emitted.push(record) } - } + class TestHandler extends Handler { + emit(record: LogRecord) { emitted.push(record) } + } + beforeEach(() => { + logger = new Logger('test', DEBUG); + emitted = []; logger.addHandler(new TestHandler(DEBUG)); - logger.debug('test message'); - expect(emitted.length).toBe(1); - expect(emitted[0].scope).toBe('test'); }); - test('does not invoke handler when level is above DEBUG', () => { - const logger = new Logger('test', WARNING); - const emitted: LogRecord[] = []; + test('debug emits at DEBUG level', () => { + logger.debug('msg'); + expect(emitted.length).toBe(1); + expect(emitted[0].levelno).toBe(DEBUG); + }); - class TestHandler extends Handler { - emit(record: LogRecord) { emitted.push(record) } - } + test('info emits at INFO level', () => { + logger.info('msg'); + expect(emitted.length).toBe(1); + expect(emitted[0].levelno).toBe(INFO); + }); - logger.addHandler(new TestHandler(DEBUG)); - logger.debug('test message'); + test('warning emits at WARNING level', () => { + logger.warning('msg'); + expect(emitted.length).toBe(1); + expect(emitted[0].levelno).toBe(WARNING); + }); + + test('error emits at ERROR level', () => { + logger.error('msg'); + expect(emitted.length).toBe(1); + expect(emitted[0].levelno).toBe(ERROR); + }); + + test('critical emits at CRITICAL level', () => { + logger.critical('msg'); + expect(emitted.length).toBe(1); + expect(emitted[0].levelno).toBe(CRITICAL); + }); + + test('level methods respect effective level', () => { + logger.setLevel(ERROR); + logger.clear(); + logger.debug('no'); + logger.info('no'); + logger.warning('no'); expect(emitted.length).toBe(0); + logger.error('yes'); + logger.critical('yes'); + expect(emitted.length).toBe(2); }); }); From fcfbd361535e8d63f643f2018642978894544e13 Mon Sep 17 00:00:00 2001 From: Tiara Rodney Date: Fri, 13 Mar 2026 22:56:15 +0100 Subject: [PATCH 3/3] todo(6): done Added info(), warning(), error(), and critical() methods to Logger, each gated by isEnabledFor(). All level methods tested including effective level filtering. --- TODO | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TODO b/TODO index 67a8ca9..3cb8d82 100644 --- a/TODO +++ b/TODO @@ -87,7 +87,7 @@ Content-Type: application/issue ID: 6 Type: feature Title: implement remaining Logger level methods -Status: in-progress +Status: done Priority: high Created: 2026-03-13 Relationships: dependsOn:5