devex: get extensions on the service logger

This commit is contained in:
KernelDeimos
2025-10-16 15:04:28 -04:00
committed by Eric Dubé
parent abcb2e9580
commit fd602aabac
2 changed files with 26 additions and 4 deletions

View File

@@ -278,12 +278,31 @@ class Extension extends AdvancedBase {
}
this.only_one_init_fn = callback;
}
get console () {
const extensionConsole = Object.create(console);
extensionConsole.log = (...a) => {
const realConsole = globalThis.original_console_object ?? console;
realConsole.log(`${display_time(new Date())} \x1B[${this.terminal_color};1m(extension/${this.name})\x1B[0m`, ...a);
let svc_log;
try {
svc_log = this.services.get('log-service');
} catch ( _e ) {
// NOOP
}
if ( ! svc_log ) {
const realConsole = globalThis.original_console_object ?? console;
realConsole.log(`${display_time(new Date())} \x1B[${this.terminal_color};1m(extension/${this.name})\x1B[0m`, ...a);
return;
}
const extensionLogger = svc_log.create(`extension/${this.name}`);
const util = require('node:util');
const consoleStyle = a.map(arg => {
if ( typeof arg === 'string' ) return arg;
return util.inspect(arg, undefined, undefined, true);
}).join(' ');
extensionLogger.info(consoleStyle);
};
return extensionConsole;
}

View File

@@ -57,7 +57,10 @@ const stringify_log_entry = ({ prefix, log_lvl, crumbs, message, fields, objects
m += prefix ? `${prefix} ` : '';
m += `\x1B[${log_lvl.esc}m[${log_lvl.label}\x1B[0m`;
for ( const crumb of crumbs ) {
for ( let crumb of crumbs ) {
if ( crumb.startsWith('extension/') ) {
crumb = `\x1B[34;1m${crumb}\x1B[0m`;
}
m += `::${crumb}`;
}
m += `\x1B[${log_lvl.esc}m]\x1B[0m`;