> -----Original Message-----
> From: Steve Downey [mailto:[EMAIL PROTECTED]] 
> Sent: Wednesday, March 06, 2002 8:07 PM
> To: 'Jakarta Commons Developers List'
> Subject: RE: [LOGGING] Request for API change (was RE: [VOTE] 
> Logging 1.0 Release (again))
> 
> 
> I'd argue that this is a misuse of a logger. A logger isn't 
> an IO stream and shouldn't be treated like one. 
> Here's how I've implement this kind of thing:
> 
> 
> public static void writeMap(Map map, Writer writer)
> {
>     for(Iterator keys = map.keySet().iterator(); keys.hasNext();)
>     {
>         String key = (String) keys.next();
>         String value = (String) map.get(key);
>         writer.print(key);
>         writer.print('=');
>         writer.print(value);
>         writer.println();
>     }
> }
> 
> ...
> if(logger.is{X}Enabled()) {
>       StringWriter writer = new StringWriter();
>       writeMap(map, writer);
>       logger.{X}(writer.toString());
> }
> 
> Now, If you want to argue that abstracting out those 4 lines 
> of code for values of X is useful, I'd argue that the 
> marginal utility is low. The number of cases where you want 
> to dump a Map to a log at levels other than debug is tiny. 
> 
Actually, I do log maps quite often.  When I'm developing and debugging,
I frequently want to dump the contents of a map.

However, I don't want this to turn into a discussion of the merits (or
lack thereof :) of logging maps. That was just an example. My desire is
to be able to abstract the logging of anything in general. My rule of
thumb is that when I write the same code more than twice, it is time to
abstract it. And as a good logger, I write lots of logging code more
than once.

BTW, I do agree that your approach to logging the map is more
appropriate. I was coding my example off the top of my head and hadn't
actually thought about a real implementation. But it still doesn't
address how the writeMap method decides which level to use.

> IOW, at Error, you want a message like "IP address not found 
> for Domain Name = {}", not a list of all known domain/IP 
> mappings. Similarly for Info "IP address {} found for Domain 
> Name = {}". Warn is something like "IP address null for 
> Domain Name = {}". Of course, these are all at the semantic 
> level above Map.
> 
> Map's internal logging should be much sparser. Earth 
> shattering events like "HashBucket claims 5 elements, but 
> only found 4: Panic!" IE, the whole thing is FUBAR'd. At 
> least until you get down to Trace level stuff. 
> 
> Just my $0.02
> 
snip
> 
Steven Caswell
[EMAIL PROTECTED]
a.k.a Mungo Knotwise of Michel Delving
"One ring to rule them all, one ring to find them..."



_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to