Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #20953

Re: dependency injection and loggers

Newsgroups comp.lang.java.programmer
Date 2013-01-04 11:36 -0800
References <e3230fa7-b672-49e0-a7ef-dfb55a9180b5@googlegroups.com> <kc6rjn$fl2$1@dont-email.me> <veFFs.21649$6a5.5075@newsfe14.iad>
Message-ID <cf3a089d-b15a-400f-9fa3-0ac37021350a@googlegroups.com> (permalink)
Subject Re: dependency injection and loggers
From Lew <lewbloch@gmail.com>

Show all headers | View raw


Daniel Pitts wrote:
> On the other hand, there generally isn't any real requirement that 
> loggers be static.  I have had occasion to create a class which uses a 
> different logger depending on the context in which that class was created.
> 
> public class MySomething {
>     private final Logger log;
> 
>     public MySomething() {
>        this.log = Logger.getLogger(MySomething.class);
>     }
> 
>     public MySomething(Logger log) {
>        this.log = log;
>     }
> }

If I have a class hierarchy (for when despite Josh Bloch's recommendation to "prefer composition 
to inheritance" I go the other way) I will often put in the parent class:

  private final Logger logger = Logger.getLogger(getClass().getName());

This despite the violation of "Don't call an overrideable method during construction."

:-)

-- 
Lew

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

dependency injection and loggers Tomer <tomerbd1@gmail.com> - 2013-01-04 04:00 -0800
  Re: dependency injection and loggers markspace <markspace@nospam.nospam> - 2013-01-04 07:13 -0800
    Re: dependency injection and loggers Kevin McMurtrie <mcmurtrie@pixelmemory.us> - 2013-01-04 09:18 -0800
      Re: dependency injection and loggers Arne Vajhøj <arne@vajhoej.dk> - 2013-01-04 22:27 -0500
        Re: dependency injection and loggers Wayne <nospam@all.invalid> - 2013-01-04 23:33 -0500
          Re: dependency injection and loggers Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-01-05 11:55 -0400
            Re: dependency injection and loggers Kevin McMurtrie <mcmurtrie@pixelmemory.us> - 2013-01-05 10:01 -0800
              Re: dependency injection and loggers Arne Vajhøj <arne@vajhoej.dk> - 2013-01-05 15:17 -0500
              Re: dependency injection and loggers Arne Vajhøj <arne@vajhoej.dk> - 2013-01-05 16:37 -0500
        Re: dependency injection and loggers Lew <lewbloch@gmail.com> - 2013-01-05 12:24 -0800
          Re: dependency injection and loggers Arne Vajhøj <arne@vajhoej.dk> - 2013-01-05 16:41 -0500
    Re: dependency injection and loggers Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2013-01-04 10:31 -0800
      Re: dependency injection and loggers Lew <lewbloch@gmail.com> - 2013-01-04 11:36 -0800
        Re: dependency injection and loggers Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2013-01-04 11:57 -0800
      Re: dependency injection and loggers Arne Vajhøj <arne@vajhoej.dk> - 2013-01-04 22:28 -0500
  Re: dependency injection and loggers Arne Vajhøj <arne@vajhoej.dk> - 2013-01-04 22:24 -0500

csiph-web