fix(DestinationLocal): Fix debug log rendering, add fallback for unknown log levels, and correct error prefix typo in local destination
This commit is contained in:
parent
a2ae8c0c83
commit
a98f48409d
@ -1,5 +1,12 @@
|
||||
# Changelog
|
||||
|
||||
## 2025-05-20 - 3.1.4 - fix(DestinationLocal)
|
||||
Fix debug log rendering, add fallback for unknown log levels, and correct error prefix typo in local destination
|
||||
|
||||
- Added tests for debug and unknown log levels in DestinationLocal
|
||||
- Refactored log string generation to use a fallback style for undefined levels
|
||||
- Fixed typo: replaced non-existent 'errorPrefix' with 'error.prefix'
|
||||
|
||||
## 2025-05-19 - 3.1.3 - fix(documentation)
|
||||
Update API reference and enhance README with detailed examples and usage instructions
|
||||
|
||||
|
@ -92,5 +92,23 @@ tap.test('should create new line(s)', async () => {
|
||||
// Multiple lines
|
||||
testDestination.newLine(3);
|
||||
});
|
||||
// Test debug level rendering and fallback for unknown levels
|
||||
tap.test('should handle debug and unknown log levels', async () => {
|
||||
testDestination = new DestinationLocal();
|
||||
let out = '';
|
||||
const originalLog = console.log;
|
||||
console.log = (msg: string) => { out += msg; };
|
||||
|
||||
// debug level should render message correctly
|
||||
await testDestination.handleLog(createMockLogPackage('debug', 'debug 🎉'));
|
||||
expect(out).toContain('debug 🎉');
|
||||
|
||||
// fallback for unknown level should still render message
|
||||
out = '';
|
||||
await testDestination.handleLog(createMockLogPackage('verbose' as any, 'verbose ⚠️'));
|
||||
expect(out).toContain('verbose ⚠️');
|
||||
|
||||
console.log = originalLog;
|
||||
});
|
||||
|
||||
export default tap.start();
|
@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartlog',
|
||||
version: '3.1.3',
|
||||
version: '3.1.4',
|
||||
description: 'A minimalistic, distributed, and extensible logging tool supporting centralized log management.'
|
||||
}
|
||||
|
@ -61,19 +61,22 @@ export class DestinationLocal implements ILogDestination {
|
||||
|
||||
// default logging
|
||||
private logToConsole(logPackageArg: ILogPackage) {
|
||||
let logString: string;
|
||||
try {
|
||||
logString =
|
||||
this.localBl[logPackageArg.level].prefix +
|
||||
const style = this.localBl[logPackageArg.level] ?? this.localBl.info;
|
||||
const logString =
|
||||
style.prefix +
|
||||
plugins.consolecolor.coloredString(
|
||||
logPackageArg.message,
|
||||
this.localBl[logPackageArg.level].textColor
|
||||
style.textColor
|
||||
);
|
||||
console.log(logString);
|
||||
return true;
|
||||
} catch (error) {
|
||||
// typo fix: use the defined error.prefix, not a non-existent errorPrefix
|
||||
console.log(
|
||||
this.localBl.errorPrefix + 'You seem to have tried logging something strange' + error
|
||||
this.localBl.error.prefix +
|
||||
'You seem to have tried logging something strange ' +
|
||||
error
|
||||
);
|
||||
return false;
|
||||
}
|
||||
@ -89,6 +92,10 @@ export class DestinationLocal implements ILogDestination {
|
||||
prefix: plugins.consolecolor.coloredString(' silly ', 'white', 'blue') + ' ',
|
||||
textColor: 'blue',
|
||||
},
|
||||
debug: {
|
||||
prefix: plugins.consolecolor.coloredString(' debug ', 'gray', 'black') + ' ',
|
||||
textColor: 'gray',
|
||||
},
|
||||
error: {
|
||||
prefix:
|
||||
plugins.consolecolor.coloredString(' ', 'red', 'red') +
|
||||
|
Loading…
x
Reference in New Issue
Block a user