fix(server): log error on gcloud (#10235)
This commit is contained in:
@@ -18,6 +18,18 @@ export class AFFiNELogger extends ConsoleLogger {
|
|||||||
return ClsServiceManager.getClsService()?.getId();
|
return ClsServiceManager.getClsService()?.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static formatStack(stackOrError?: Error | string | unknown) {
|
||||||
|
if (stackOrError instanceof Error) {
|
||||||
|
const err = stackOrError;
|
||||||
|
let stack = err.stack ?? '';
|
||||||
|
if (err.cause instanceof Error && err.cause.stack) {
|
||||||
|
stack += `\n\nCaused by:\n\n${err.cause.stack}`;
|
||||||
|
}
|
||||||
|
return stack;
|
||||||
|
}
|
||||||
|
return stackOrError;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Nestjs ConsoleLogger.error() will not print the stack trace if the error is an instance of Error
|
* Nestjs ConsoleLogger.error() will not print the stack trace if the error is an instance of Error
|
||||||
* This method is a workaround to print the stack trace
|
* This method is a workaround to print the stack trace
|
||||||
@@ -32,15 +44,6 @@ export class AFFiNELogger extends ConsoleLogger {
|
|||||||
stackOrError?: Error | string | unknown,
|
stackOrError?: Error | string | unknown,
|
||||||
context?: string
|
context?: string
|
||||||
) {
|
) {
|
||||||
let stack = '';
|
super.error(message, AFFiNELogger.formatStack(stackOrError), context);
|
||||||
if (stackOrError instanceof Error) {
|
|
||||||
const err = stackOrError;
|
|
||||||
stack = err.stack ?? '';
|
|
||||||
if (err.cause instanceof Error && err.cause.stack) {
|
|
||||||
stack += `\n\nCaused by:\n\n${err.cause.stack}`;
|
|
||||||
}
|
|
||||||
stackOrError = stack;
|
|
||||||
}
|
|
||||||
super.error(message, stackOrError, context);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,10 @@ export class AFFiNELogger extends WinstonLogger {
|
|||||||
stackOrError?: Error | string | unknown,
|
stackOrError?: Error | string | unknown,
|
||||||
context?: string
|
context?: string
|
||||||
) {
|
) {
|
||||||
RawAFFiNELogger.prototype.error.call(this, message, stackOrError, context);
|
super.error(
|
||||||
|
message,
|
||||||
|
RawAFFiNELogger.formatStack(stackOrError) as string,
|
||||||
|
context
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user