Ver Fonte

dev: add injected logger support

This allows a logger to be specified in the execution context. If
LogService sees this, it will perform its usual logging but also call
the injected logger.
KernelDeimos há 1 mês atrás
pai
commit
a3ae60861c

+ 5 - 0
src/backend/src/modules/core/LogService.js

@@ -112,6 +112,11 @@ class LogContext {
                 typeof fields[k].toLogFields === 'function'
                 typeof fields[k].toLogFields === 'function'
             ) fields[k] = fields[k].toLogFields();
             ) fields[k] = fields[k].toLogFields();
         }
         }
+        if ( Context.get('injected_logger') ) {
+            Context.get('injected_logger').log(
+                message + (fields ? ('; fields: ' + JSON.stringify(fields)) : ''),
+            );
+        }
         this.logService.log_(
         this.logService.log_(
             log_level,
             log_level,
             this.crumbs,
             this.crumbs,

+ 3 - 1
src/backend/src/services/CommandService.js

@@ -134,7 +134,9 @@ class CommandService extends BaseService {
         * @returns {Promise<void>}
         * @returns {Promise<void>}
         * @throws {Error} If command execution fails
         * @throws {Error} If command execution fails
         */
         */
-        await globalThis.root_context.arun(async () => {
+        await globalThis.root_context.sub({
+            injected_logger: log,
+        }).arun(async () => {
             await command.execute(commandArgs, log);
             await command.execute(commandArgs, log);
         });
         });
     }
     }