mirror of
https://github.com/HeyPuter/puter.git
synced 2026-01-07 05:30:31 -06:00
devex: get extensions on the service logger
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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`;
|
||||
|
||||
Reference in New Issue
Block a user