Slf4j LoggerFactory.getLogger and sonarqube

2019-02-15 14:03发布

问题:

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

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

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]+)*$'"

What is wrong?

回答1:

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

  • 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