mirror of
https://github.com/HeyPuter/puter
synced 2024-11-14 22:06:00 +00:00
devex: add command to start/stop recording logs to a file
This commit is contained in:
parent
eb17d61fc1
commit
d14a30e089
@ -161,6 +161,7 @@ class DevLogger {
|
||||
constructor (log, opt_delegate) {
|
||||
this.log = log;
|
||||
this.off = false;
|
||||
this.recto = null;
|
||||
|
||||
if ( opt_delegate ) {
|
||||
this.delegate = opt_delegate;
|
||||
@ -179,11 +180,19 @@ class DevLogger {
|
||||
const prefix = globalThis.dev_console_indent_on
|
||||
? Array(ld ?? 0).fill(' ').join('')
|
||||
: '';
|
||||
this.log(stringify_log_entry({
|
||||
this.log_(stringify_log_entry({
|
||||
prefix,
|
||||
log_lvl, crumbs, message, fields, objects,
|
||||
}));
|
||||
}
|
||||
|
||||
log_ (text) {
|
||||
if ( this.recto ) {
|
||||
const fs = require('node:fs');
|
||||
fs.appendFileSync(this.recto, text + '\n');
|
||||
}
|
||||
this.log(text);
|
||||
}
|
||||
}
|
||||
|
||||
class NullLogger {
|
||||
@ -291,6 +300,28 @@ class LogService extends BaseService {
|
||||
this.devlogger && (this.devlogger.off = ! this.devlogger.off);
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'rec',
|
||||
description: 'start recording to a file via dev logger',
|
||||
handler: async (args, ctx) => {
|
||||
const [name] = args;
|
||||
const {log} = ctx;
|
||||
if ( ! this.devlogger ) {
|
||||
log('no dev logger; what are you doing?');
|
||||
}
|
||||
this.devlogger.recto = name;
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'stop',
|
||||
description: 'stop recording to a file via dev logger',
|
||||
handler: async ([name], log) => {
|
||||
if ( ! this.devlogger ) {
|
||||
log('no dev logger; what are you doing?');
|
||||
}
|
||||
this.devlogger.recto = null;
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'indent',
|
||||
description: 'toggle log indentation',
|
||||
|
Loading…
Reference in New Issue
Block a user