Merge branch 'feature/6' into dev
This commit is contained in:
commit
2bdcb17ee6
3 changed files with 79 additions and 20 deletions
2
TODO
2
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
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue