added stack trace to some logging
This commit is contained in:
@@ -49,17 +49,29 @@ const logFormat = winston.format.combine(
|
||||
const { timestamp, level, message, stack, ...metadata } = info;
|
||||
let output = `${timestamp} ${level}: ${message}`;
|
||||
|
||||
// Check for stack trace in the info object itself
|
||||
if (stack) {
|
||||
output += `\n${stack}`;
|
||||
// Include relevant metadata in console output
|
||||
const metaKeys = Object.keys(metadata).filter(key =>
|
||||
!['splat', 'Symbol(level)', 'Symbol(message)'].includes(key) &&
|
||||
!key.startsWith('Symbol')
|
||||
);
|
||||
|
||||
if (metaKeys.length > 0) {
|
||||
const metaOutput = {};
|
||||
metaKeys.forEach(key => {
|
||||
// For Error objects, extract message and stack
|
||||
if (metadata[key] && metadata[key].stack) {
|
||||
metaOutput[key] = { message: metadata[key].message, stack: metadata[key].stack };
|
||||
} else {
|
||||
metaOutput[key] = metadata[key];
|
||||
}
|
||||
});
|
||||
output += ` ${JSON.stringify(metaOutput, null, 2)}`;
|
||||
}
|
||||
|
||||
// Check for Error objects in metadata
|
||||
Object.keys(metadata).forEach(key => {
|
||||
if (metadata[key] && metadata[key].stack) {
|
||||
output += `\n${key}: ${metadata[key].message}\n${metadata[key].stack}`;
|
||||
}
|
||||
});
|
||||
// Check for stack trace in the info object itself
|
||||
if (stack) {
|
||||
output += `\nStack: ${stack}`;
|
||||
}
|
||||
|
||||
return output;
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user