Apify and Crawlee Official Forum

Updated 2 months ago

How to override `maxRequestRetries` error log

there is a function
Plain Text
    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?
W
2 comments
I just want to know how can I ger rid of these defaut logs...
Attachment
image.png
okey I manage to do it with my proxy class:

Plain Text
 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'
    }
  }
Add a reply
Sign up and join the conversation on Discord