[slf4j-dev] addChildLogger method

Ceki Gülcü listid at qos.ch
Mon Jul 11 22:34:27 CEST 2005


If POJOs can be injected Logger objects, why can't they be injected
LoggerFactory objects?

Let MyClass be written:

import org.slf4j.LoggerFactorAdapter;

  public class MyClass  {
       private MyOtherClass m_other1;
       private MyOtherClass m_other2;

        public MyClass( LoggerFactorAdapter loggerFactory )
        {
            Logger logger = loggerFactory.getLogger(MyClass.class);
            m_other1 = new MyOtherClass( loggerFactory, 10 );
            m_other2 = new MyOtherClass( loggerFactory, 20 );
        }
    }


"Give a man a fish; you have fed him for today.  Teach a man to fish;
and you have fed him for a lifetime." -- Author unknown

At 10:18 PM 7/11/2005, you wrote:


>On 2005-05-05, Niclas Hedhman wrote:
>
> > If the addChildLogger is in the ULogger interface, it could be a
> > recommended pattern to do;
> >
> >   public class MyClass
> >   {
> >       private MyOtherClass m_other1;
> >       private MyOtherClass m_other2;
> >
> >       public MyClass( ULogger logger )
> >       {
> >           ULogger child1 = logger.addChildLogger( "other1" );
> >           m_other1 = new MyOtherClass( child1, 10 );
> >           ULogger child2 = logger.addChildLogger( "other2" );
> >           m_other2 = new MyOtherClass( child2, 20 );
> >       }
> >   }
> >
> > in which case the IoC principle is propagated to POJOs, and will
> > greatly help in unittesting.

-- 
Ceki Gülcü

   The complete log4j manual: http://www.qos.ch/log4j/





More information about the slf4j-dev mailing list