用户登录
用户注册

分享至

Slf4j LoggerFactory.getLogger 和 sonarqube

  • 作者: 亖呉?盀
  • 来源: 51数据库
  • 2022-10-28

问题描述

初始化Slf4j LoggerFactory.getLogger的正确方法是什么?我的代码中有

What is the correct way to initialize Slf4j LoggerFactory.getLogger? I have in my code

static final Logger logger = LoggerFactory.getLogger(MyClass.class);

但 sonarqube 代码分析将此代码标记为重大错误:"重命名此常量名称以匹配正则表达式'^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$'"

But sonarqube code analysis marks this code as major error: "Rename this constant name to match the regular expression '^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$'"

怎么了?

推荐答案

常量(静态final)变量在Java中一般都是大写的.所以你可以:

Constants (static final) variables are generally in upper case in Java. So you can either:

  • 在这种特殊情况下忽略注释(在记录器中使用小型大写字母并不罕见)
  • 将 logger 重命名为其他名称,例如 LOG
  • ignore the comment in this particular case (it is not unusual to use small caps for the logger)
  • rename logger into something else, for example LOG
软件
前端设计
程序设计
Java相关