logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gary Gregory <garydgreg...@gmail.com>
Subject New traceEntry code
Date Mon, 08 Feb 2016 17:17:43 GMT
Hi All:

The pattern I've had to implement for our product is close to what this
does, but not quite, so I'd like to propose changes.

The key part is for the new traceEntry methods to return the String message
it built so I can reuse it in the traceExit() call. This is how I do it now:

public int doFoo(int a, int b) {
  final String method = traceEntry("doFoo(a=%,d, b=%,d", a, b);
  // do Foo impl
  int result = ...
  return traceExit(method, result);
}

This allows the Entry/Exit log events to match nicely, especially in our
multi-threaded use cases. It's easier to tell which exit matches which
entry. You do not want to compute the method String more than once of
course.

(I use the String.format() message factory to get nice looking numbers, and
so on. We allow that to be set up at the logger level, which is nice.)

I've had to cookup my own my own traceEntry/traceExit, otherwise the code
would be logger.traceEntry(...).

The verbiage I use is also different: I use a verb: "Enter", as opposed to
the noun "entry", which looks really weird in English to me. "Entry
methodName"? That does not sound good to me "Entry of methodName" OK. For
me it's "Enter methodName..." and "Exit methodName". Sentences start with a
cap too.

It's too late to change the API names but the wording should be fixed
(calling it broken is my opinion of course) or configurable.

The new methods are missing @since Javadoc tags

I could only find a unit for 1 of the new APIs, did I miss the others?

I'll experiment unless I hear howls of horror...

Gary
-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message