<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=davsclaus" rel="nofollow">Claus Ibsen</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-601?redirect=false" rel="nofollow">SPR-601</a></strong> and commented</p>
<p dir="auto">I forked the org.springframework.aop.interceptors.TraceInterceptor as I needed several added functionality. I ended up adding a few more features and made it customizable so I could contribute it back to the Spring team.</p>
<p dir="auto">I have attached a modified version of the TraceInterceptor.java with these enhancements:</p>
<ul dir="auto">
<li>possible to customize output formating of ENTER and EXIT messages</li>
<li>possible to output elapsed time</li>
<li>possible to output method arguments</li>
<li>possible to use dynamic logger name (using the classname of the method invocation = just as if you had written to log code in the class itself. See example)</li>
</ul>
<p dir="auto">Using the dynamic logname makes it possible to output logs as:</p>
<p dir="auto">http8080-Processor4 07 jan 2005 11:22:58 DEBUG dk.netfragt.pbs.NetfragtPBSWebService - ENTER - accepterFaktura<br>
dk.netfragt.pbs.NetfragtPBSWebService - EXIT  - accepterFaktura. Time = 1656 msec.</p>
<p dir="auto">Instead of the default:</p>
<p dir="auto">http8080-Processor4 07 jan 2005 11:19:43 DEBUG org.springframework.aop.interceptor.TraceInterceptor - Entering method accepterFaktura in class [dk.netfragt.pbs.NetfragtPBSWebService]</p>
<p dir="auto">And with the method arguments you can see what has been passed in as arguments (in this example 77777):</p>
<p dir="auto">http8080-Processor4 07 jan 2005 11:19:43 DEBUG org.springframework.aop.interceptor.TraceInterceptor - Entering method accepterFaktura(77777) in class [dk.netfragt.pbs.NetfragtPBSWebService]</p>
<p dir="auto">And you can change the formatting of the message using java.text.Format with {0} placeholders. The defaults are:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="private String enterMessage = &quot;Entering method {1}{2} in class [{0}]&quot;;
private String exitMessage = &quot;Exiting method {1}{2} in class [{0}]&quot;;"><pre class="notranslate"><code class="notranslate">private String enterMessage = "Entering method {1}{2} in class [{0}]";
private String exitMessage = "Exiting method {1}{2} in class [{0}]";
</code></pre></div>
<p dir="auto">You can customize this in the spring .xml configuration:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&lt;bean id=&quot;traceInterceptor&quot; class=&quot;org.springframework.aop.interceptor.TraceInterceptor&quot;&gt;
	&lt;property name=&quot;elapsedTime&quot;&gt;&lt;value&gt;true&lt;/value&gt;&lt;/property&gt;
	&lt;property name=&quot;arguments&quot;&gt;&lt;value&gt;true&lt;/value&gt;&lt;/property&gt;
	&lt;property name=&quot;dynamicLogName&quot;&gt;&lt;value&gt;true&lt;/value&gt;&lt;/property&gt;
	&lt;property name=&quot;enterMessage&quot;&gt;&lt;value&gt;ENTER - {1}{2}&lt;/value&gt;&lt;/property&gt;
	&lt;property name=&quot;exitMessage&quot;&gt;&lt;value&gt;EXIT  - {1}{2}&lt;/value&gt;&lt;/property&gt;
&lt;/bean&gt;"><pre class="notranslate"><code class="notranslate">&lt;bean id="traceInterceptor" class="org.springframework.aop.interceptor.TraceInterceptor"&gt;
	&lt;property name="elapsedTime"&gt;&lt;value&gt;true&lt;/value&gt;&lt;/property&gt;
	&lt;property name="arguments"&gt;&lt;value&gt;true&lt;/value&gt;&lt;/property&gt;
	&lt;property name="dynamicLogName"&gt;&lt;value&gt;true&lt;/value&gt;&lt;/property&gt;
	&lt;property name="enterMessage"&gt;&lt;value&gt;ENTER - {1}{2}&lt;/value&gt;&lt;/property&gt;
	&lt;property name="exitMessage"&gt;&lt;value&gt;EXIT  - {1}{2}&lt;/value&gt;&lt;/property&gt;
&lt;/bean&gt;
</code></pre></div>
<p dir="auto">Using the above will output:</p>
<p dir="auto">http8080-Processor4 07 jan 2005 11:22:58 DEBUG dk.netfragt.pbs.NetfragtPBSWebService - ENTER - accepterFaktura(676767)<br>
http8080-Processor4 07 jan 2005 11:23:00 DEBUG dk.netfragt.pbs.NetfragtPBSWebService - EXIT  - accepterFaktura(676767). Time = 1656 msec.</p>
<p dir="auto">As the example above illustrates that using dynamicLogName and customizing the log message it is possible to change it radically.</p>
<p dir="auto">I hope the Spring team could accept these changes as the default version is the same as the existing one.</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 1.1.3</p>
<p dir="auto"><strong>Attachments:</strong></p>
<ul dir="auto">
<li><a href="https://jira.spring.io/secure/attachment/10632/TraceInterceptor.java" rel="nofollow">TraceInterceptor.java</a> (<em>7.50 kB</em>)</li>
<li><a href="https://jira.spring.io/secure/attachment/10421/TraceInterceptor.java" rel="nofollow">TraceInterceptor.java</a> (<em>5.55 kB</em>)</li>
</ul>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398056252" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/5586" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/5586/hovercard" href="https://github.com/spring-projects/spring-framework/issues/5586">#5586</a> [PATCH] Enhancements to TraceInterceptor (<em><strong>"is duplicated by"</strong></em>)</li>
</ul>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=costin" rel="nofollow">Costin Leau</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-1625?redirect=false" rel="nofollow">SPR-1625</a></strong> and commented</p>
<p dir="auto">A lot of users on the forum have problems setting up an application using the OpenSessionInView. Most of the times the solution is outside the spring samples at points at various blogs or demo applications. I think a simple OSIV (mainly with Hibernate) should be added inside the main distribution samples (even if as a comment).</p>
<hr>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398075724" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/7879" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/7879/hovercard" href="https://github.com/spring-projects/spring-framework/issues/7879">#7879</a> OpenSessionInView Filter/Interceptor lacks documentation coverage (<em><strong>"is duplicated by"</strong></em>)</li>
</ul>
<p dir="auto">5 votes, 5 watchers</p>