Details
-
Type:
New Feature
-
Status:
Resolved
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: 1.8
-
Fix Version/s: 1.8.1
-
Component/s: None
-
Labels:None
Description
The default configuration in log4j.properties file is
log4j.appender.stdout.layout.ConversionPattern=[@APPNAME@] %p [%t]
%C
.%M(%L) | %m%n
As per the log4j manual:
%C: Outputs the fully-qualified class name of the caller issuing the
logging request.
%c: Outputs the category of the logging event.
This setting of uppercase 'C' causes problem while using org.springframework.aop.interceptor.CustomizableTraceInterceptor .
Given below is the detaile explanation of the problem.
TestA.java {
protected final Log log = LogFactory.getLog(getClass());
log.debug("this message is from TestA
;
}
This will produce the log message like this:
DEBUG ( org.mycompany.TestA:methodName) - this message is from TestA
Now let's assume that the use decides to use
CustomizableTraceInterceptor. Now the log message for entry will look
like this.
DEBUG ( org.springframework.aop.interceptor.CustomizableTraceInterceptor:methodName)
- Entering method .......
DEBUG ( org.mycompany.TestA:methodName) - this message is from TestA
Notice that the debug message is coming from
"CustomizableTraceInterceptor". If instead of using aop I had used the
log message in the code then the message should be
DEBUG ( org.mycompany.TestA:methodName) - Entering method .......
To achieve the stated goal above one could set "useDynamicLogge" to true.
<property name="useDynamicLogger" value="true" />
If I make the configuration change mentioned above and test the code
again. The log message would still say
DEBUG ( org.springframework.aop.interceptor.CustomizableTraceInterceptor:methodName)
- Entering method .......
Why? The spring is doing it's job of creating the logger with TestA
but in the log4j.properties we have mentioned to output the name of
the class that is creating the log message by specifying uppercase
'.C'. If we change the log4j.properties file to have lowercase 'c'
then the logger that is spitting the log messages is displayed and we
will get the message as given below.
DEBUG ( org.mycompany.TestA:methodName) - Entering method .......
DEBUG ( org.mycompany.TestA:methodName) - this message is from TestA
Now looking at this log message one can't say that the 'entering
method' log is create using AOP. That's truly transparent AOP in action.
The result is exactly same as if the log message was coded in the
application.
Activity
| Field | Original Value | New Value |
|---|---|---|
| Fix Version/s | 1.8.1 [ 10002 ] | |
| Affects Version/s | 1.8 [ 10000 ] |
| Status | Open [ 1 ] | Resolved [ 5 ] |
| Resolution | Fixed [ 1 ] |