diff --git a/continew-admin-common/src/main/java/top/charles7c/cnadmin/common/handler/GlobalExceptionHandler.java b/continew-admin-common/src/main/java/top/charles7c/cnadmin/common/handler/GlobalExceptionHandler.java index 5a06a332..f0184927 100644 --- a/continew-admin-common/src/main/java/top/charles7c/cnadmin/common/handler/GlobalExceptionHandler.java +++ b/continew-admin-common/src/main/java/top/charles7c/cnadmin/common/handler/GlobalExceptionHandler.java @@ -97,7 +97,7 @@ public class GlobalExceptionHandler { @ResponseStatus(HttpStatus.BAD_REQUEST) @ExceptionHandler(BadRequestException.class) public R handleBadRequestException(BadRequestException e, HttpServletRequest request) { - log.error("请求地址'{}',自定义验证失败", request.getRequestURI(), e); + log.warn("请求地址'{}',自定义验证失败", request.getRequestURI(), e); LogContextHolder.setErrorMsg(e.getMessage()); return R.fail(HttpStatus.BAD_REQUEST.value(), e.getMessage()); } @@ -108,7 +108,7 @@ public class GlobalExceptionHandler { @ResponseStatus(HttpStatus.BAD_REQUEST) @ExceptionHandler(BindException.class) public R handleBindException(BindException e, HttpServletRequest request) { - log.error("请求地址'{}',参数验证失败", request.getRequestURI(), e); + log.warn("请求地址'{}',参数验证失败", request.getRequestURI(), e); String errorMsg = StreamUtils.join(e.getAllErrors(), DefaultMessageSourceResolvable::getDefaultMessage, ","); LogContextHolder.setErrorMsg(errorMsg); return R.fail(HttpStatus.BAD_REQUEST.value(), errorMsg); @@ -120,7 +120,7 @@ public class GlobalExceptionHandler { @ResponseStatus(HttpStatus.BAD_REQUEST) @ExceptionHandler(ConstraintViolationException.class) public R constraintViolationException(ConstraintViolationException e, HttpServletRequest request) { - log.error("请求地址'{}',参数验证失败", request.getRequestURI(), e); + log.warn("请求地址'{}',参数验证失败", request.getRequestURI(), e); String errorMsg = StreamUtils.join(e.getConstraintViolations(), ConstraintViolation::getMessage, ","); LogContextHolder.setErrorMsg(errorMsg); return R.fail(HttpStatus.BAD_REQUEST.value(), errorMsg); @@ -132,7 +132,7 @@ public class GlobalExceptionHandler { @ResponseStatus(HttpStatus.BAD_REQUEST) @ExceptionHandler(MethodArgumentNotValidException.class) public R handleMethodArgumentNotValidException(MethodArgumentNotValidException e, HttpServletRequest request) { - log.error("请求地址'{}',参数验证失败", request.getRequestURI(), e); + log.warn("请求地址'{}',参数验证失败", request.getRequestURI(), e); String errorMsg = ExceptionUtils .exToNull(() -> Objects.requireNonNull(e.getBindingResult().getFieldError()).getDefaultMessage()); LogContextHolder.setErrorMsg(errorMsg); @@ -147,7 +147,7 @@ public class GlobalExceptionHandler { public R handleMethodArgumentTypeMismatchException(MethodArgumentTypeMismatchException e, HttpServletRequest request) { String subMsg = StrUtil.format("参数名:'{}',期望参数类型:'{}'", e.getName(), e.getParameter().getParameterType()); - log.error("请求地址'{}',参数转换失败。方法:'{}',{}", request.getRequestURI(), + log.warn("请求地址'{}',参数转换失败。方法:'{}',{}", request.getRequestURI(), Objects.requireNonNull(e.getParameter().getMethod()).getName(), subMsg, e); LogContextHolder.setErrorMsg(subMsg); return R.fail(HttpStatus.BAD_REQUEST.value(), subMsg); @@ -170,7 +170,7 @@ public class GlobalExceptionHandler { @ResponseStatus(HttpStatus.BAD_REQUEST) @ExceptionHandler(MaxUploadSizeExceededException.class) public R handleMaxUploadSizeExceededException(MaxUploadSizeExceededException e, HttpServletRequest request) { - log.error("请求地址'{}',上传文件失败,文件大小超过限制", request.getRequestURI(), e); + log.warn("请求地址'{}',上传文件失败,文件大小超过限制", request.getRequestURI(), e); String sizeLimit = StrUtil.subBetween(e.getMessage(), "The maximum size ", " for"); String errorMsg = String.format("请上传小于 %s MB 的文件", NumberUtil.parseLong(sizeLimit) / 1024 / 1024); LogContextHolder.setErrorMsg(errorMsg); diff --git a/continew-admin-common/src/main/java/top/charles7c/cnadmin/common/util/ExcelUtils.java b/continew-admin-common/src/main/java/top/charles7c/cnadmin/common/util/ExcelUtils.java index d3906457..072ed47f 100644 --- a/continew-admin-common/src/main/java/top/charles7c/cnadmin/common/util/ExcelUtils.java +++ b/continew-admin-common/src/main/java/top/charles7c/cnadmin/common/util/ExcelUtils.java @@ -27,7 +27,6 @@ import lombok.extern.slf4j.Slf4j; import com.alibaba.excel.EasyExcel; import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy; -import com.esotericsoftware.minlog.Log; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.URLUtil; @@ -90,7 +89,7 @@ public class ExcelUtils { // 自动转换大数值 .registerConverter(new ExcelBigNumberConverter()).sheet(sheetName).doWrite(list); } catch (Exception e) { - Log.error("Export excel occurred an error.", e); + log.error("Export excel occurred an error: {}. fileName: {}.", e.getMessage(), fileName, e); throw new ServiceException("导出 Excel 出现错误"); } } diff --git a/continew-admin-common/src/main/java/top/charles7c/cnadmin/common/util/FileUtils.java b/continew-admin-common/src/main/java/top/charles7c/cnadmin/common/util/FileUtils.java index 405bc423..aa2299f8 100644 --- a/continew-admin-common/src/main/java/top/charles7c/cnadmin/common/util/FileUtils.java +++ b/continew-admin-common/src/main/java/top/charles7c/cnadmin/common/util/FileUtils.java @@ -56,16 +56,16 @@ public class FileUtils { String originalFilename = multipartFile.getOriginalFilename(); String extensionName = FileNameUtil.extName(originalFilename); - String filename; + String fileName; if (isKeepOriginalFilename) { - filename = String.format("%s-%s.%s", FileNameUtil.getPrefix(originalFilename), + fileName = String.format("%s-%s.%s", FileNameUtil.getPrefix(originalFilename), DateUtil.format(LocalDateTime.now(), StringConsts.PURE_DATE_TIME_MS_PATTERN), extensionName); } else { - filename = String.format("%s.%s", IdUtil.fastSimpleUUID(), extensionName); + fileName = String.format("%s.%s", IdUtil.fastSimpleUUID(), extensionName); } try { - String pathname = filePath + filename; + String pathname = filePath + fileName; File dest = new File(pathname).getCanonicalFile(); // 如果父路径不存在,自动创建 if (!dest.getParentFile().exists()) { @@ -77,7 +77,7 @@ public class FileUtils { multipartFile.transferTo(dest); return dest; } catch (Exception e) { - log.error(e.getMessage(), e); + log.error("Upload file occurred an error: {}. fileName: {}.", e.getMessage(), fileName, e); } return null; } diff --git a/continew-admin-common/src/main/java/top/charles7c/cnadmin/common/util/helper/QueryHelper.java b/continew-admin-common/src/main/java/top/charles7c/cnadmin/common/util/helper/QueryHelper.java index c094b20e..6afd1690 100644 --- a/continew-admin-common/src/main/java/top/charles7c/cnadmin/common/util/helper/QueryHelper.java +++ b/continew-admin-common/src/main/java/top/charles7c/cnadmin/common/util/helper/QueryHelper.java @@ -119,7 +119,7 @@ public class QueryHelper { // 解析查询条件 parse(queryAnnotation, field.getName(), fieldValue, queryWrapper); } catch (Exception e) { - log.error(e.getMessage(), e); + log.error("Build query occurred an error: {}. Query: {}, Field: {}.", e.getMessage(), query, field, e); } finally { field.setAccessible(accessible); } diff --git a/continew-admin-webapi/src/main/resources/logback-spring.xml b/continew-admin-webapi/src/main/resources/logback-spring.xml index 1fc5aac3..bf03f497 100644 --- a/continew-admin-webapi/src/main/resources/logback-spring.xml +++ b/continew-admin-webapi/src/main/resources/logback-spring.xml @@ -36,19 +36,19 @@ + + ${LOG_PATH}/${APP_NAME}.log + + + + ${LOG_PATH}/${APP_NAME}.log.%d{yyyy-MM-dd}.gz + + 15 + ${FILE_LOG_PATTERN} ${LOG_CHARSET} - - - - ${LOG_PATH}/%d{yyyy-MM-dd, aux}/${APP_NAME}.%d{yyyy-MM-dd_HH}.%i.log - - 240 - - 20MB -