mirror of
https://github.com/HeyPuter/puter.git
synced 2025-12-30 09:40:00 -06:00
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.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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');
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user