Re: [Codenarc-user] LoggerWithWrongModifiersRule supporting subclasses
Brought to you by:
chrismair
From: R. S. <ren...@go...> - 2011-05-31 08:45:33
|
It's not about the "protected" (this is just required). The interesting part is the non-static one. Because of it, a superclass uses the logger of the derived class based on "getLogger(this.class)". With such a logger it's for example possible to write every log message of a class (including its superclass) to a separate file because they are using the same logger. Regards, René Scheibe On 05/31/2011 09:55 AM, Hamlet DArcy wrote: > Personally, I would require loggers to be static, private, and final. > If someone really needed a protected logger then i would still make it static and final, just protected. > > So I think we need both these settings. > > > > ----- Original Message ----- >> That's a great question. >> >> I do use that pattern in framework superclasses: >> protected final LOG = Logger.getLogger(this.class) >> >> to provide a built-in logger for all subclasses. And so I have to >> configure >> exceptions for this rule for those superclasses. >> >> Is there any value in splitting up the "exception" configuration into >> two >> properties, if we do allow it? >> * allowNonStaticLogger >> * allowProtectedLogger >> >> Are there use cases we can envision where we (or anyone) would choose >> to >> allow non-static but not protected, or vice versa? >> >> Chris >> -----Original Message----- >> From: Hamlet D'Arcy [mailto:ham...@gm...] >> Sent: Monday, May 30, 2011 2:50 AM >> To: René Scheibe; Cod...@li... >> Subject: [Codenarc-user] LoggerWithWrongModifiersRule supporting >> subclasses >> >> Hi everyone, >> >> This email is about the idea about the LoggerWithWrongModifiersRule >> supporting subclasses. >> >> René filed an issue (and supplied a patch) describing the issue: >> https://sourceforge.net/tracker/index.php?func=detail&aid=3308930&group_id=2 >> 50145&atid=1126575# >> >> Basically, the question is how subclasses should be allowed to access >> a >> Logger in a parent class. >> >> Normally Loggers are private, static, and final. This patch allows >> you to >> accept this as valid code when you turn a certain property on: >> >> protected final LOG = Logger.getLogger(this.class) >> >> I'd like to discuss this just a little more before committing the >> patch. >> >> With this change, it is acceptable to have a non-static logger. So >> each >> instance of a subclass makes and creates a logger. This does not seem >> right, >> and I would reject it in a code review as improper logging. I would >> accept >> this form though: >> >> protected static final LOG = Logger.getLogger(MyClass.class) >> >> Do we really want to allow non-static Loggers? >> >> if so, I recommend two new properties instead of just one: >> * allowNonStaticLogger >> * allowProtectedLogger >> >> Then the user can control the behavior a little better. >> >> >> >> -- >> Hamlet D'Arcy >> ham...@gm... >> >> ---------------------------------------------------------------------------- >> -- >> vRanger cuts backup time in half-while increasing security. >> With the market-leading solution for virtual backup and recovery, you >> get >> blazing-fast, flexible, and affordable data protection. >> Download your free trial now. >> http://p.sf.net/sfu/quest-d2dcopy1 >> _______________________________________________ >> Codenarc-user mailing list >> Cod...@li... >> https://lists.sourceforge.net/lists/listinfo/codenarc-user >> >> >> ------------------------------------------------------------------------------ >> Simplify data backup and recovery for your virtual environment with >> vRanger. >> Installation's a snap, and flexible recovery options mean your data >> is safe, >> secure and there when you need it. Data protection magic? >> Nope - It's vRanger. Get your free trial download today. >> http://p.sf.net/sfu/quest-sfdev2dev >> _______________________________________________ >> Codenarc-user mailing list >> Cod...@li... >> https://lists.sourceforge.net/lists/listinfo/codenarc-user >> |