From 9529d87e31a7aa207adbf3a47ec14d2f7237293d Mon Sep 17 00:00:00 2001 From: KernelDeimos <7225168+KernelDeimos@users.noreply.github.com> Date: Thu, 16 Oct 2025 17:13:14 -0400 Subject: [PATCH] devex: add log tracing feature simply set `trace_logs` to `true` in your config and you can easily figure out where logs are coming from. --- src/backend/doc/log_config.md | 8 ++++++++ src/backend/src/modules/core/LogService.js | 4 ++++ src/backend/src/modules/core/lib/log.js | 6 +++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/backend/doc/log_config.md b/src/backend/doc/log_config.md index bb678195..72f50ff4 100644 --- a/src/backend/doc/log_config.md +++ b/src/backend/doc/log_config.md @@ -21,6 +21,14 @@ Sometimes "enabling" a log means moving its log level from `debug` to `info`. - `http`: http requests - `fsentries-not-found`: information about files that were stat'd but weren't there +#### Other log options + +- Setting `log_upcoming_alarms` to `true` will log alarms before they are created. + This would be useful if AlarmService itself is failing. +- Setting `trace_logs` to `true` will display a stack trace below every log message. + This can be useful if you don't know where a particular log is coming from and + want to track it down. + #### Service-level log configuration Services can be configured to change their logging behavior. Services will have one of diff --git a/src/backend/src/modules/core/LogService.js b/src/backend/src/modules/core/LogService.js index 40aa2062..80d630b0 100644 --- a/src/backend/src/modules/core/LogService.js +++ b/src/backend/src/modules/core/LogService.js @@ -607,6 +607,10 @@ class LogService extends BaseService { try { // skip messages that are above the output level if ( log_lvl.ordinal > this.output_lvl ) return; + + if ( this.config.trace_logs ) { + fields.stack = (new Error('logstack')).stack; + } for ( const logger of this.loggers ) { logger.onLogMessage( diff --git a/src/backend/src/modules/core/lib/log.js b/src/backend/src/modules/core/lib/log.js index 88a07ae8..0d6b941c 100644 --- a/src/backend/src/modules/core/lib/log.js +++ b/src/backend/src/modules/core/lib/log.js @@ -38,7 +38,7 @@ const config = require('../../../config.js'); * @param {Object} objects - Objects to be logged. * @returns {string} A formatted string representation of the log entry. */ -const stringify_log_entry = ({ prefix, log_lvl, crumbs, message, fields, objects }) => { +const stringify_log_entry = ({ prefix, log_lvl, crumbs, message, fields, objects, stack }) => { const { colorize } = require('json-colorizer'); let lines = [], m; @@ -94,6 +94,7 @@ const stringify_log_entry = ({ prefix, log_lvl, crumbs, message, fields, objects } if ( k === 'timestamp' ) continue; + if ( k === 'stack' ) continue; let v; try { v = colorize(JSON.stringify(fields[k])); } catch (e) { @@ -102,6 +103,9 @@ const stringify_log_entry = ({ prefix, log_lvl, crumbs, message, fields, objects m += ` \x1B[1m${k}:\x1B[0m ${v}`; lf(); } + if ( fields.stack ) { + lines.push(fields.stack); + } return lines.join('\n'); };