From d14a30e08970b363a352c1adbae2a03fa0d4c1a1 Mon Sep 17 00:00:00 2001 From: KernelDeimos Date: Wed, 19 Jun 2024 15:49:58 -0400 Subject: [PATCH] devex: add command to start/stop recording logs to a file --- .../services/runtime-analysis/LogService.js | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/packages/backend/src/services/runtime-analysis/LogService.js b/packages/backend/src/services/runtime-analysis/LogService.js index dac11194..8566513b 100644 --- a/packages/backend/src/services/runtime-analysis/LogService.js +++ b/packages/backend/src/services/runtime-analysis/LogService.js @@ -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',