Spring DebugInterceptor: AOP Trace Logging for Development


Publication Date:

Updated:


INFORMATION > Spring DebugInterceptor: AOP Trace Logging for Development

Bottom line: Spring's DebugInterceptor is a proxy-based AOP interceptor that logs verbose method-invocation details at TRACE level. It is intended for debugging, not as a general production observability strategy.

What you'll learn

  • How an advisor selects methods and attaches the interceptor to eligible Spring beans.
  • Why self-invocation and objects created outside the Spring container can bypass proxy advice.
  • How to avoid exposing arguments, personal data, credentials, or excessive log volume.

Who this is for: Spring developers maintaining an XML-configured application or learning classic proxy-based AOP.

2026 context: The class still exists in current Spring Framework documentation, but the Spring 5.1.4 XML example below is historical. Use a supported Spring line, limit TRACE logging to controlled diagnostics, and prefer current metrics, tracing, and structured logging for production operations.

Overview

This is about how to use Spring's DebugInterceptor. I understood the concept from the following Spring website, but it was difficult to understand how to do it concretely from the website alone.

https://docs.spring.io/spring-framework/reference/core/aop-api.html

Table of Contents

  1. What is DebugInterceptor?
  2. Configuration (historical Spring 5.1.4 example)
  3. Conclusion

1. What is DebugInterceptor?

DebugInterceptor is a library that outputs logs by AOP. Specifically, the following libraries (jar files) are used. Version 5.1.4.

https://repo1.maven.org/maven2/org/springframework/spring-aop/5.1.4.RELEASE/

The specific Java file is "org.springframework.aop.interceptor.DebugInterceptor.

To briefly explain AOP, AOP is a technique for injecting processing into instances managed on Spring's DI container. The official name for AOP is Aspect Oriented Programming.

In this case, inject DebugInterceptor into the instance created by @Component.

1-1. implementation environment

The JAR and version used are listed below because behavior can differ by environment.

Version of spring aopspring-aop-5.1.4.RELEASE.jar
Version of spring beansspring-beans-5.1.4.RELEASE.jar
Log output library versionslf4j-api-1.7.25.jar
logback-core-1.2.3.jar

1-2. Work required

The required tasks are as follows

  • Create an instance with @Component
  • Define AOP in applicationContext.xml
  • Change log output settings

2. Configuration (historical Spring 5.1.4 example)

The next step implements the configuration.

2-1. Create an instance with @Component

Prepare a class with "@Component" declared as follows. Since we only want to see the AOP, only "return" is executed.

TestAop.java


@Component
public class TestAop{
    public void testMethod() {

        return;

    }

}

2-2. Define AOP in applicationContext.xml

Set up AOP to inject the process. The red will be the part related to the AOP.

applicationContext.xml


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:util="http://www.springframework.org/schema/util"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd">
~omission~
    <!-- Spring AOP Testing. -->
    <bean id="debugInterceptor" class="org.springframework.aop.interceptor.DebugInterceptor" />
    <aop:config>
        <aop:advisor advice-ref="debugInterceptor"
            pointcut="execution(* com.example.TestAop.testMethod(..))"  />
    </aop:config>
</beans>

The "pointcut" is written as follows

pointcut="execution(* Package Name.class name.method name(..))"

In the above example, it would be as follows

• Package Name: com.example

• class name: TestAop

• method name: testMethod

To match every method in the target package, use the broader pointcut shown below.

• pointcut="execution(* com.example.TestAop.*(..))"

2-3. Change log output settings

Since the level of log output listed in DebugInterceptor is "TRACE", change the log level only in DebugInterceptor. The red areas are the ones that need to be set. The other settings can be entered arbitrarily.

logback.xml


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration>
<configuration>

    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern><![CDATA[date:%d{yyyy-MM-dd HH:mm:ss}\tthread:%thread\tX-Track:%X{X-Track}\tlevel:%-5level\tlogger:%-48logger{48}\tmessage:%msg%n]]></pattern>
        </encoder>
    </appender>

    <appender name="APPLICATION_LOG_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${app.log.dir:-log}/todo-application.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${app.log.dir:-log}/todo-application-%d{yyyyMMdd}.log</fileNamePattern>
            <maxHistory>7</maxHistory>
        </rollingPolicy>
        <encoder>
            <charset>UTF-8</charset>
            <pattern><![CDATA[date:%d{yyyy-MM-dd HH:mm:ss}\tthread:%thread\tX-Track:%X{X-Track}\tlevel:%-5level\tlogger:%-48logger{48}\tmessage:%msg%n]]></pattern>
        </encoder>
    </appender>

    <logger name="org.springframework.aop.interceptor" level="trace">
        <appender-ref ref="STDOUT" />
        <appender-ref ref="APPLICATION_LOG_FILE" />
    </logger>

    <root level="warn">
        <appender-ref ref="STDOUT" />
        <appender-ref ref="APPLICATION_LOG_FILE" />
    </root>

</configuration>

I looked at some other people's blogs when creating this file, and some of them stated that the output should be at log level DEBUG, but in the case of "spring-aop-5.1.4.RELEASE.jar", it seems that the output is not output unless the log level TRACE is used.

If the configuration should be working well, but for some reason the logs are not outputting, try changing the log level to TRACE.

2-4. result

When testMethod of TestAop.java is called with the above settings completed, the following log should be output. The log is long, so I deleted a few lines, but there should be two lines for "Entering (start of processing)" and "Exiting (end of processing)," for a total of four lines of output.

date:2021-01-18 15:26:35	thread:http-nio-8081-exec-3	X-Track:84b8ab0aa6504352a815ce85167a1981	level:TRACE	logger:o.s.aop.interceptor.DebugInterceptor	message:Entering ReflectiveMethodInvocation 
date:2021-01-18 15:26:35	thread:http-nio-8081-exec-3	X-Track:84b8ab0aa6504352a815ce85167a1981	level:TRACE	logger:o.s.aop.interceptor.DebugInterceptor	message:Entering ReflectiveMethodInvocation 
date:2021-01-18 15:26:40	thread:http-nio-8081-exec-3	X-Track:84b8ab0aa6504352a815ce85167a1981	level:TRACE	logger:o.s.aop.interceptor.DebugInterceptor	message:Exiting ReflectiveMethodInvocation 
date:2021-01-18 15:26:40	thread:http-nio-8081-exec-3	X-Track:84b8ab0aa6504352a815ce85167a1981	level:TRACE	logger:o.s.aop.interceptor.DebugInterceptor	message:Exiting ReflectiveMethodInvocation 

3. Conclusion

Use DebugInterceptor only for controlled diagnostics, limit the pointcut, and verify that sensitive arguments or return values are not written to logs.

Official references