This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 106324 - Introduce a method to create per-module loggers
Summary: Introduce a method to create per-module loggers
Status: RESOLVED WONTFIX
Alias: None
Product: platform
Classification: Unclassified
Component: -- Other -- (show other bugs)
Version: 6.x
Hardware: All All
: P3 blocker (vote)
Assignee: apireviews
URL:
Keywords: API, API_REVIEW_FAST
Depends on:
Blocks:
 
Reported: 2007-06-11 22:08 UTC by Andrei Badea
Modified: 2008-12-22 14:35 UTC (History)
0 users

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments
Proposed change (6.16 KB, text/plain)
2007-06-11 22:10 UTC, Andrei Badea
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andrei Badea 2007-06-11 22:08:55 UTC
Inspired by NbPreferences.forModule(), which returns a Preferences node for the
whole module, I propose a method to create per-module java.util.logging.Logger's. 

This method could be useful in modules which need to log in a few places only
and would use Logger.global if that was permitted. It could also help keep the
number of loggers down (no logger per class unless really needed) while avoiding
forcing users to come up with their own scheme of maintaining a logger per
module. It e.g. be used to replace ErrorManager.getDefault().log() calls, where
it could be a better choice than Logger.getLogger(Foo.class.getName()).log().

I would like this method to be NbLogger.forModule(), but Yarda preferred
Exceptions in order to avoid yet another small class in o.o.util, so it's
Exceptions.getLogger().

I will add Javadoc, tests, etc. if the feedback is encouraging.
Comment 1 Andrei Badea 2007-06-11 22:10:06 UTC
Created attachment 43529 [details]
Proposed change
Comment 2 David Vancouvering 2007-06-11 22:17:32 UTC
Very nice, I like this feature, and plan to use it when the need arises.  Code
looks good.
Comment 3 Jesse Glick 2007-06-11 22:23:30 UTC
What's wrong with simply calling Logger.getLogger(clazz.getName())? I don't see
the problem with having one logger per class. In fact it seems preferable since
you leave open the option of finer-grained control over logging levels.
Comment 4 Andrei Badea 2007-06-11 23:05:16 UTC
Nothing is wrong with it, with the exception that it creates unnecessary loggers
which live forever. If in a module that doesn't otherwise make use of logging I
need to log a warning in three classes, I have just created three loggers, which
seems too much for what I need to do.

You're right about the fine-grained control, but when you need to do that you
have probably already devised a logging scheme, you would need more control over
your loggers and wouldn't need Exception.getLogger(), which is intended for the
simple cases.
Comment 5 Jesse Glick 2007-06-12 03:40:26 UTC
Is there actually any noticeable overhead per logger instance? Have you measured?

You don't need any particular "scheme" just to call
Logger.getLogger(ThisClass.class.getName()). Seems pretty simple already.
Comment 6 Milos Kleint 2007-06-12 08:18:10 UTC
+1 on Jesse's objections.

If deemed useful however, I think your original idea of NbLogger.forModule() is
easier to find and use than Exceptions.getLogger().

Comment 7 _ rkubacki 2007-06-12 09:08:44 UTC
So far I did not see logging code to be a bottleneck for our runtime performance
or memory consumption. Logger creating is very fast action and it is lightweight
data structure usually held by static field in your class and through hashtable
in j.u.l.LogManager. While talking about cost: the proposal brings yet another
contract into global lookup to be able to get module base name.

If you really want only a few occurrences of logging code why not to use package
private Logger (using class or package name).

Comment 8 Andrei Badea 2007-06-12 22:49:34 UTC
OK, closing then.