generator-jhipster: Minor bug in LoggingAspect

Overview of the issue In the generated LoggingAspect class, the following method has a minor bug

@AfterThrowing(pointcut = "loggingPointcut()", throwing = "e")
public void logAfterThrowing(JoinPoint joinPoint, Throwable e) {
    if (env.acceptsProfiles(Constants.SPRING_PROFILE_DEVELOPMENT)) {
        log.error("Exception in {}.{}() with cause = {}", joinPoint.getSignature().getDeclaringTypeName(),
            joinPoint.getSignature().getName(), e.getCause(), e);
    } else {
        log.error("Exception in {}.{}() with cause = {}", joinPoint.getSignature().getDeclaringTypeName(),
            joinPoint.getSignature().getName(), e.getCause());
    }
}

The log.error() method accepts 4 arguments in the if condition block but has only 3 {} placeholders in the format.

On a slightly related note: The log field on this class could be made static final

private static final Logger LOG = LoggerFactory.getLogger(LoggingAspect.class);

instead of

private final Logger log = LoggerFactory.getLogger(this.getClass());

Jhipster version 2.23.0

Reproduce the error Create a jhipster project normally. I don’t think there is a special scenario when this code is generated this way.

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 15 (15 by maintainers)

Most upvoted comments

@vivekmore then that’s another issue, please our guidelines say we should have only one issue per ticket

  • this has already been discussed in the past
  • I find it more logical not to put them static as they don’t need to be (waste of characters, and might put people under the false assumption the Spring bean isn’t a singleton)
  • it’s not even recommended by tools like SLF4J ( http://www.slf4j.org/faq.html#declared_static )
  • we don’t use non-singleton scopes in the project (and in which case, it would indeed make sense, and they would just show that the users understand what they actually do instead of blindly copy/pasting code all over the place, see my first point)
  • and that’s a personal preference of mine, but if you put them static final, then you would need to write them in upper case, which looks like you’re shouting all over the place, and brings the eye on the logging statements, which are probably the less important stuff in the code