如何在Spring Boot中禁用某些警告

huangapple go评论129阅读模式
英文:

How to disable some warnings in Spring Boot

问题

在我的应用程序中,我可以上传文件(最大大小为10MB)。我为了处理过大的文件创建了一个异常处理程序,但控制台仍然显示警告,表示尝试上传了过大的文件:

2020-09-30 01:38:59.306  WARN 2476 --- [nio-8080-exec-3] .m.m.a.ExceptionHandlerExceptionResolver : Resolved [org.springframework.web.multipart.MaxUploadSizeExceededException: Maximum upload size exceeded; nested exception is java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.impl.SizeLimitExceededException: the request was rejected because its size (26937892) exceeds the configured maximum (10485760)]

异常处理程序:

    @ExceptionHandler(MaxUploadSizeExceededException.class)
    public void oversizedFilesHandler(MaxUploadSizeExceededException e){
        accountService.writeExceptionToFile(e);
    }

是否有可能禁用这些警告?

英文:

in my app i can upload files (max size is 10MB). I created an exception handler for too big files, but console still shows warning that there was a try to upload too big file:

2020-09-30 01:38:59.306  WARN 2476 --- [nio-8080-exec-3] .m.m.a.ExceptionHandlerExceptionResolver : Resolved [org.springframework.web.multipart.MaxUploadSizeExceededException: Maximum upload size exceeded; nested exception is java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.impl.SizeLimitExceededException: the request was rejected because its size (26937892) exceeds the configured maximum (10485760)]

Exception handler:

    @ExceptionHandler(MaxUploadSizeExceededException.class)
    public void oversizedFilesHandler(MaxUploadSizeExceededException e){
        accountService.writeExceptionToFile(e);
    }

Is it possible to disable these warnings?

答案1

得分: 3

你可以通过将日志级别添加到你的属性文件中来实现:

规则: logging.level.xxxx=LEVEL

其中:

  • LEVEL 是以下之一:TRACE、DEBUG、INFO、WARN、ERROR、FATAL、OFF

  • xxxx 是一个包/类。

我们将规则应用于你的情况:

logging.level.org.springframework.web=ERROR

甚至更精细:

logging.level.org.springframework.web.multipart=ERROR

因此,只有 ERROR、FATAL 和 OFF 级别的日志将被记录到你的控制台。

英文:

You can achieve that by adding log level to your properties file:

RULE : logging.level.xxxx=LEVEL

where:

  • LEVEL is one of TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF.

  • xxxx is a package/class.

We apply the rule to your case:

logging.level.org.springframework.web=ERROR 

Or even thinner:

logging.level.org.springframework.web.multipart =ERROR 

Hence, only ERROR, FATAL and OFF level will be logged to you console.

huangapple
  • 本文由 发表于 2020年9月30日 08:11:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/64129252.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定