How to override `maxRequestRetries` error log

there is a function
protected async _handleFailedRequestHandler(crawlingContext: Context, error: Error): Promise<void> {
// Always log the last error regardless if the user provided a failedRequestHandler
const { id, url, method, uniqueKey } = crawlingContext.request;
const message = this._getMessageFromError(error, true);

this.log.error(`Request failed and reached maximum retries. ${message}`, { id, url, method, uniqueKey });

if (this.failedRequestHandler) {
await this._tagUserHandlerError(() =>
this.failedRequestHandler?.(this._augmentContextWithDeprecatedError(crawlingContext, error), error),
);
}
}
protected async _handleFailedRequestHandler(crawlingContext: Context, error: Error): Promise<void> {
// Always log the last error regardless if the user provided a failedRequestHandler
const { id, url, method, uniqueKey } = crawlingContext.request;
const message = this._getMessageFromError(error, true);

this.log.error(`Request failed and reached maximum retries. ${message}`, { id, url, method, uniqueKey });

if (this.failedRequestHandler) {
await this._tagUserHandlerError(() =>
this.failedRequestHandler?.(this._augmentContextWithDeprecatedError(crawlingContext, error), error),
);
}
}
that is triggered once maxRequestRetries is done, how could I override this log message with my own? I don't want to see whole stacktrace in my logs, I just want to notify that there is an error and details can be found under some id in DB should I disable logs for error and handle them manually?
3 Replies
Hall
Hall7mo ago
View post on community site
This post has been pushed to the community knowledgebase. Any replies in this thread will be synced to the community site.
Apify Community
extended-salmon
extended-salmonOP7mo ago
I just want to know how can I ger rid of these defaut logs...
No description
extended-salmon
extended-salmonOP7mo ago
okey I manage to do it with my proxy class:
private getLogMethod(level: LogLevel): keyof Logger {
switch (level) {
case LogLevel.DEBUG:
case LogLevel.PERF:
case LogLevel.WARNING:
case LogLevel.ERROR: // do not display error level in console
return 'debug'
case LogLevel.INFO:
return 'info'
case LogLevel.SOFT_FAIL: // in code use this.log.softFail to display your error logs
return 'error'
default:
return 'info'
}
}
private getLogMethod(level: LogLevel): keyof Logger {
switch (level) {
case LogLevel.DEBUG:
case LogLevel.PERF:
case LogLevel.WARNING:
case LogLevel.ERROR: // do not display error level in console
return 'debug'
case LogLevel.INFO:
return 'info'
case LogLevel.SOFT_FAIL: // in code use this.log.softFail to display your error logs
return 'error'
default:
return 'info'
}
}

Did you find this page helpful?