views:

106

answers:

3

I am looking for a library that does logging on a higher abstraction layer then Log4J or similiar.

Instead of calling the framework once for every row of logging needed, I want to call it once per at the beginning of the action, once at the successful ending and possibly once if an exception occured.

The logging framework should then create logging entries for start, end, duration, number of times this action was performed in 5 minutes, time spend in the various modules/layers (identified by package naming conventions).

Does anything like this exist? In Java?

Note: I am not interested to much in hints how to implement that myself. I am doing this right now and just want to know if I am reinventing the wheel.

+3  A: 

I don't know of an existing logging framework that addresses your concerns (which does not mean that such a framework does not exist...) but I think that AOP mechanisms like the ones offered by Spring or AspectJ may help you. So, you need to check whether you are reinventing their pointcut/weaving facilities.

Itay
No I won't because I would use them
Jens Schauder
+3  A: 

It sounds like you don't want a "logging" framework, you want a "profiling" framework.

Depending on what you mean by the term "action", what you want might already be part of the JVM... check out the older JVMPI and the newer JVMTI.

The list of events ("actions") you can trigger on includes Method entry or exit, Exceptions thrown or caught, Thread start or end, GC events, etc...

The built-in implementation using this in the jvm is hprof. If you're handy with the command line, it can give you a decent picture of what's going on...

http://www.yourkit.com/ used to be a good commercial product, but I haven't used it in a long time.

Eclipse and Netbeans both have JVMTI plugins these days, which should be able to tell you how often each of your methods is called, how long they run, and how many objects they create and/or destroy...

Stobor
You are kind of right. Profiling might be the correct term, but I want it on a domain logic level, not on a programming language level. My actions would be things like "saveOrder", basically anything that get's triggered either by a user or by a client, depending on the kind of application.
Jens Schauder
+2  A: 

There is some work done on a profiler in a logging setting in the SLF4J project, but I am not certain that it would be high level enough for you. You might be inspired though :)

Have a look at http://slf4j.org/extensions.html#profiler

Thorbjørn Ravn Andersen
That is pretty close, and handles quite some stuff I need. Also some good ideas. Great.
Jens Schauder