lundi 26 septembre 2016

How to dynamically generate a stack frame with debug log information

For better debugging, I would often like to have:

Exception 
  at com.example.blah.Something.method()
  at com.example.blah.Xyz.otherMethod()
  at com.example.hello.World.foo()
  at com.example.debug.version_3_8_0.debug_info_something.Hah.method() // synthetic method
  at com.example.x.A.wrappingMethod()

The debug stack frame as shown above would be dynamically generated, just like a java.lang.reflect.Proxy, except that I'd like to be in full control of the entire fully qualified method name that ends up on the proxy.

At the call site, I would do something silly and simple as this:

public void wrappingMethod() {
    run("com.example.debug.version_3_8_0.debug_info_something.Hah.method()", () -> {
        World.foo();
    });
}

As you can see, the wrappingMethod() is a real method that ends up on the stack trace, Hah.method() is a dynamically generated method, whereas World.foo() is again a real method.

Yes, I know this pollutes the already deep deep stack traces. Don't worry about it. I have my reasons.

Is there a (simple) way to do this or something similar as the above?





Aucun commentaire:

Enregistrer un commentaire