It happens in situations like 
Foo:method1—>Logger.log—>DBAppender.append—>Hibernate.something—>Logger.log.  
It is actually pretty common when you create appenders that want to interact 
with third party libraries.  For example, an Appender might use Netty to 
interact with sockets, Thrift to access some NoSQL package, etc.

getCallerClass() only returns the Class object where I would need typically 
need the StackTraceElement (or StackFrame) and the Class. Traversing through 
how getCallerClass() is implemented it wasn’t clear to me exactly how it was 
getting the Class since I haven’t spent a lot of time looking at 
CallerClassFinder, AbstractStackWalker, etc and haven’t looked at all at how 
callStackWalker is implemented.

But my point is that if obtaining the StackFrame and Class could be done so 
quickly that it wouldn’t add any noticeable overhead we could do that in every 
Logger.info, debug, etc. call.  If we could just get the stack frame index so 
that we could obtain the StackFrame and Class later by using the index that 
would be even better since we would only be creating the StackFrame, etc if it 
is really required.

Ralph

> On May 11, 2016, at 9:35 AM, Daniel Fuchs <daniel.fu...@oracle.com> wrote:
> 
> Hi Ralph,
> 
> On 11/05/16 18:14, Ralph Goers wrote:
>> You are correct that most of the time it would be faster to start from frame 
>> 0. However, the problem we have with walking the stack from frame 0 is that 
>> it is possible to have a situation like
>> 
>> Foo::method1—>Logger.log—>BarAppender.append—>Foo::method2 (or even method1 
>> again)—>Logger.log
> 
> The appender would call Logger.log? Is that a common situation?
> That sounds strange to me.
> 
> I was kind of assuming that you could walk the stack until
> finding an instance of Logger (which would allow you to skip
> all the appender's infrastructure), then continue walking until
> you find something which is no longer a Logger.
> 
> I'm not sure I understand your other comment about getCallerClass().
> That just walks 2 frames (skipping reflection frame).
> You can do the same with StackWalker, that should enable you
> to get the calling frame easily.
> 
> best regards,
> 
> -- daniel
> 


Reply via email to