Hi All:

[Preface: Some of this might seem heretic to the purist but it comes from
pragmatic experience of working with a lot of code from a lot of different
folks]

For most of my Java apps, in DEBUG mode, I log the system properties at
some point on start up.

The cheap solution is the obvious:

logger.debug(System.getProperties());

The same idea applies, depending on my app for network interfaces and
character sets.

Having one giant line is not easy to read, even in a word-wrapped editor.

What I do instead is log one message per map entry.

I go even further and explode the entries like the classpath (but let's
KISS for now.)

This works great for the console and files but I can imagine that this
would be suboptimal for JMS. As always, caveat emptor.

Could Log4J 2.0 do something like this?

*Part 1:*

It is tempting to add methods like:

/** Logs one message per map entry in the form "key = value". */
*debugMap*(Map<?, ?> map)
*debugMap*(Map<?, ?> map, String separator)

*Part 2:*

I then wonder how we could handle the explosion of map entries with some
kind of callback.

Even if we did not, and the explosion was handled in the app itself, I
would like to be able to log my exploded messages in one go with a
collection like method:

/** Logs one message per Iterable value. */
*debugAll*(Iterable<?> iterable)

*Part 3:*

Back to exploding an object. This seems best handled in app code because
even with some callback, all the code in the app, so nothing is gained.

Thoughts?

*Part 4:*

This is lame:

logger.debug(NetworkInterface.getNetworkInterfaces());

It outputs:

15:47:44.624 [main] DEBUG org.apache.logging.log4j.core.BasicLoggingTest -
java.net.NetworkInterface$1@1ccce3c

I would rather call:

/** Logs one message per Enumeration value. */
*debugAll*(Enumeration<?> enumeration)

Whatever Log4J can do for me to help me DEBUG apps without my needing add
util code over and over.

*Part 5:*

Most folks might not need this, but we do:

logger.debug(Charset.availableCharsets());

If I have *debugMap*, then it's pretty.

Thank you reading this *far*!

Gary

-- 
E-Mail: [email protected] | [email protected]
JUnit in Action, 2nd Ed: <http://goog_1249600977>http://bit.ly/ECvg0
Spring Batch in Action: <http://s.apache.org/HOq>http://bit.ly/bqpbCK
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Reply via email to