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
|
ID: 6
|
||||||
Type: feature
|
Type: feature
|
||||||
Title: implement remaining Logger level methods
|
Title: implement remaining Logger level methods
|
||||||
Status: in-progress
|
Status: done
|
||||||
Priority: high
|
Priority: high
|
||||||
Created: 2026-03-13
|
Created: 2026-03-13
|
||||||
Relationships: dependsOn:5
|
Relationships: dependsOn:5
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,11 @@
|
||||||
import {
|
import {
|
||||||
LogLevel,
|
LogLevel,
|
||||||
DEBUG,
|
DEBUG,
|
||||||
NOTSET,
|
INFO,
|
||||||
WARNING,
|
WARNING,
|
||||||
|
ERROR,
|
||||||
|
CRITICAL,
|
||||||
|
NOTSET,
|
||||||
checkLevel,
|
checkLevel,
|
||||||
} from './log-level';
|
} from './log-level';
|
||||||
import {
|
import {
|
||||||
|
|
@ -173,6 +176,34 @@ export class Logger extends Filterer {
|
||||||
if (this.isEnabledFor(DEBUG)) { this._log(DEBUG, msg, options) }
|
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
|
* A factory method which can be overriden in subclasses to create
|
||||||
* specialized LogRecords.
|
* specialized LogRecords.
|
||||||
|
|
|
||||||
|
|
@ -124,32 +124,60 @@ describe('Logger', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('debug', () => {
|
describe('level methods', () => {
|
||||||
test('invokes handler when level is DEBUG', () => {
|
let logger: Logger;
|
||||||
const logger = new Logger('test', DEBUG);
|
let emitted: LogRecord[];
|
||||||
const emitted: LogRecord[] = [];
|
|
||||||
|
|
||||||
class TestHandler extends Handler {
|
class TestHandler extends Handler {
|
||||||
emit(record: LogRecord) { emitted.push(record) }
|
emit(record: LogRecord) { emitted.push(record) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
logger = new Logger('test', DEBUG);
|
||||||
|
emitted = [];
|
||||||
logger.addHandler(new TestHandler(DEBUG));
|
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', () => {
|
test('debug emits at DEBUG level', () => {
|
||||||
const logger = new Logger('test', WARNING);
|
logger.debug('msg');
|
||||||
const emitted: LogRecord[] = [];
|
expect(emitted.length).toBe(1);
|
||||||
|
expect(emitted[0].levelno).toBe(DEBUG);
|
||||||
|
});
|
||||||
|
|
||||||
class TestHandler extends Handler {
|
test('info emits at INFO level', () => {
|
||||||
emit(record: LogRecord) { emitted.push(record) }
|
logger.info('msg');
|
||||||
}
|
expect(emitted.length).toBe(1);
|
||||||
|
expect(emitted[0].levelno).toBe(INFO);
|
||||||
|
});
|
||||||
|
|
||||||
logger.addHandler(new TestHandler(DEBUG));
|
test('warning emits at WARNING level', () => {
|
||||||
logger.debug('test message');
|
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);
|
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