<%#
 Copyright 2013-2017 the original author or authors from the JHipster project.

 This file is part of the JHipster project, see https://jhipster.github.io/
 for more information.

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-%>
package <%=packageName%>.aop.logging;

import io.github.jhipster.config.JHipsterConstants;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.env.Environment;

import java.util.Arrays;

/**
 * Aspect for logging execution of service and repository Spring components.
 *
 * By default, it only runs with the "dev" profile.
 */
@Aspect
public class LoggingAspect {

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

    private final Environment env;

    public LoggingAspect(Environment env) {
        this.env = env;
    }

    /**
     * Pointcut that matches all repositories, services and Web REST endpoints.
     */
    @Pointcut("(within(<%=packageName%>.repository..*) && @annotation(org.springframework.stereotype.Repository))"+
        " || (within(<%=packageName%>.service..*) && @annotation(org.springframework.stereotype.Service))"+
        " || (within(<%=packageName%>.web.rest..*) && @annotation(org.springframework.web.bind.annotation.RestController))")
    public void loggingPointcut() {
        // Method is empty as this is just a Pointcut, the implementations are in the advices.
    }

    /**
     * Advice that logs methods throwing exceptions.
     *
     * @param joinPoint join point for advice
     * @param e exception
     */
    @AfterThrowing(pointcut = "loggingPointcut()", throwing = "e")
    public void logAfterThrowing(JoinPoint joinPoint, Throwable e) {
        if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT)) {
            log.error("Exception in {}.{}() with cause = \'{}\' and exception = \'{}\'", joinPoint.getSignature().getDeclaringTypeName(),
                joinPoint.getSignature().getName(), e.getCause() != null? e.getCause() : "NULL", e.getMessage(), e);

        } else {
            log.error("Exception in {}.{}() with cause = {}", joinPoint.getSignature().getDeclaringTypeName(),
                joinPoint.getSignature().getName(), e.getCause() != null? e.getCause() : "NULL");
        }
    }

    /**
     * Advice that logs when a method is entered and exited.
     *
     * @param joinPoint join point for advice
     * @return result
     * @throws Throwable throws IllegalArgumentException
     */
    @Around("loggingPointcut()")
    public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {
        if (log.isDebugEnabled()) {
            log.debug("Enter: {}.{}() with argument[s] = {}", joinPoint.getSignature().getDeclaringTypeName(),
                joinPoint.getSignature().getName(), Arrays.toString(joinPoint.getArgs()));
        }
        try {
            Object result = joinPoint.proceed();
            if (log.isDebugEnabled()) {
                log.debug("Exit: {}.{}() with result = {}", joinPoint.getSignature().getDeclaringTypeName(),
                    joinPoint.getSignature().getName(), result);
            }
            return result;
        } catch (IllegalArgumentException e) {
            log.error("Illegal argument: {} in {}.{}()", Arrays.toString(joinPoint.getArgs()),
                joinPoint.getSignature().getDeclaringTypeName(), joinPoint.getSignature().getName());

            throw e;
        }
    }
}

@@ -1679,63 +1679,16 @@
 ut(%22
-(
 within(
-%3C%25=packageName%25%3E.repository..*) && @annotation(
+@
 org.
@@ -1724,19 +1724,21 @@
 pository
-)
+ *
 )%22
+ 
 +%0A      
@@ -1748,60 +1748,16 @@
  %7C%7C 
-(
 within(
-%3C%25=packageName%25%3E.service..*) && @annotation(
+@
 org.
@@ -1790,19 +1790,21 @@
 .Service
-)
+ *
 )%22
+ 
 +%0A      
@@ -1814,116 +1814,446 @@
  %7C%7C 
-(
 within(
-%3C%25=packageName%25%3E.web.rest..*) && @annotation(org.springframework.web.bind.annotation.RestController)
+@org.springframework.web.bind.annotation.RestController *)%22)%0A    public void springBeanPointcut() %7B%0A        // Method is empty as this is just a Pointcut, the implementations are in the advices.%0A    %7D%0A%0A    /**%0A     * Pointcut that matches all Spring beans in the application's main packages.%0A     */%0A    @Pointcut(%22within(com.yolo.repository..*)%22+%0A        %22 %7C%7C within(com.yolo.service..*)%22+%0A        %22 %7C%7C within(com.yolo.web.rest..*
 )%22)%0A
@@ -2268,23 +2268,34 @@
 ic void 
-logging
+applicationPackage
 Pointcut
@@ -2580,23 +2580,58 @@
 tcut = %22
-logging
+applicationPackagePointcut() && springBean
 Pointcut
@@ -3522,23 +3522,58 @@
 Around(%22
-logging
+applicationPackagePointcut() && springBean
 Pointcut

Correct the pointcut as the @annotation doesn’t work on class-level annotations