Somehow I think this information should be provided in an accompanying readme or incorporated into the javadoc for the class.
-Mark > -----Original Message----- > From: Jacob Kjome [mailto:[EMAIL PROTECTED]] > Sent: Thursday, December 12, 2002 10:10 PM > To: Log4J Developers List > Subject: Re: ClassLoader Repository Selector inclusion > > > > I thought I should add a note about Log4jCRS so people can understand how > it is differently implemented than the way Ceki describes it in his doc > http://www.qos.ch/logging/sc.html ). > > <quote name="Ceki"> > > The Servlet Container will set the repository selector to a CRS instance > when it starts up. This is as simple as calling: > > Object guard = new Object(); > LogManager.setRepositorySelector(new CRS(), guard); > > > Thereafter, the repository selector can only be changed by supplying the > guard. Those who do not know it cannot change the repository > selector. Note > that the CRS implementation is Container specific i.e. it is part of the > Container, not log4j. > </quote> > > In fact, this version of Log4jCRS is *not* "part of the > Container". It is > driven by applications individually. Tomcat needs to know absolutely > nothing about this class for multiple applications to utilize it. > > Here is how it works... > > First, Log4jCRS and log4j.jar need to be in the same classloader. > This can > be either WEB-INF/lib or a parent classloader like Tomcat's common/lib > (note that classes in shared/lib count as being in the same > classloader as > common/lib). The case of using the WEB-INF/lib kind of defeats > the purpose > of using this at all since Log4j already has a unique logging environment > to work within, but it works, nevertheless. What we'll assume for the > following is that log4j.jar and Log4jCRS exist in common/lib (and/or > shared/lib...although log4j.jar needs to be in common/lib or else > Tomcat's > commons-logging goes bonkers). > > > Each application, at startup, configures Log4j in the init() method of a > servlet or in the contextInitialized() method of a servlet > context listener > (the latter being the best choice). Before any call to any configure() > method, the following gets run... > > Log4jCRS crs = new Log4jCRS(); > crs.initLoggerRepository(); > > Now call your favorite configure() method. > > That's it! A new LoggerRepository has been created uniquely for your > application keyed upon the WebappClassLoader of the current webapp. All > other webapps do the same thing. Again, Tomcat is none-the-wiser > and your > code doesn't even know it happened. You set up your loggers and your > configuration just like you always did. You need no special knowledge > about Log4jCRS except just before running your app's configuration. > > Now you say, "but how do I clean up after logging"? "I have to shut down > appenders when my app shuts down (and the VM/Tomcat continues to > run) or my > files will be locked if I am using, for instance, a FileAppender". Well, > Log4jCRS comes to the rescue there as well.... > > Using the contextDestroyed() method of a servlet context > listener, one can > do the following.... > > ClassLoader cl = Thread.currentThread().getContextClassLoader(); > Log4jCRS crs = Log4jCRS.getCRS(cl); > crs.getLoggerRepository().shutdown(); > crs.remove(cl); > > That last line is less important since, with that classloader no > longer in > existence and the fact that it is stored in a WeakHashMap, it will clean > itself up, eventually. However, since it is convenient, we just do it > ourselves anyway. > > To sum up... > We are able to create a unique LoggerRepository for any webapp that wants > one even with log4j existing in the heterogeneous environment of > the parent > classloader where, normally, it would be used statically with the same > LoggerRepository for all apps if not for Log4jCRS. And all this is done > without Tomcat having a clue as to the fact that we are using a custom > logger repository selector! > > Caveat!!!! > The classes that load Log4jCRS *must* exist in the WebappClassLoader of > *each* webapp. So, if you have a Log4jInit servlet or a servlet context > listener that initializes Log4j, they must be loaded from WEB-INF/lib or > WEB-INF/classes. This is because when Log4jCRS is loaded, it uses the > classloader that loaded it as the key for the logger repositories. > > So, Log4jCRS *must* exist in or beside log4j.jar *and* the classes that > load Log4jCRS *must* exist in the WebappClassLoader. > > If you can accept that, then I think you will enjoy using Log4jCRS. > > There you go. Now you are informed. > > Jake > > > At 02:41 PM 12/12/2002 -0800, you wrote: > >OK, it has been discussed on the user list. Is this something we want to > >include in the official distribution? Here is what I think, everyone can > >chime in: > > > >1) Yes. It is a good, useful implementation and example of a > >RepositorySelector. > >2) Place it in the package org.apache.log4j.selectors. > >3) Rename the class to ClassLoaderRepositorySelector or > ClassLoaderSelector. > >4) Unless there is a good reason not to, include it in the > log4j.jar, not a > >separate jar. > > > >It's not a vote. It's a discussion. :-) > > > >-Mark > > > >-----Original Message----- > >From: Jacob Kjome [mailto:[EMAIL PROTECTED]] > >Sent: Thursday, December 12, 2002 2:15 PM > >To: Log4J Users List > >Subject: Re[6]: Log4j Configuration with Servlet > > > > > >Hello Mark, > > > >Here it is (zip file attached). > > > >I set the package as org.apache.log4j.spi and commented out the > >imports from that package. If it is going to a separate package, feel > >free to modify it. > > > >Jake > > > >Thursday, December 12, 2002, 3:53:38 PM, you wrote: > > > >MW> I'm sure there is, but I think any log4j source file will > provide enough > >MW> example. It is basically just the license header info at the top, > >AFAIK. > > > >MW> -Mark > > > > >> -----Original Message----- > > >> From: Jacob Kjome [mailto:[EMAIL PROTECTED]] > > >> Sent: Thursday, December 12, 2002 1:48 PM > > >> To: Log4J Users List > > >> Subject: Re[4]: Log4j Configuration with Servlet > > >> > > >> > > >> MW> Jacob, do you think you can make an "official" apache > > >> submission (with all > > >> MW> the correct apache headers, etc)? > > >> > > >> Is there some place that describes all that, or should I > just copy the > > >> license from some other Log4j file and paste it into Log4jCRS? > > >> > > >> Jake > > >> > > >> > > >> -- > > >> To unsubscribe, e-mail: > > >> <mailto:[EMAIL PROTECTED]> > > >> For additional commands, e-mail: > > >> <mailto:[EMAIL PROTECTED]> > > >> > > > >MW> -- > >MW> To unsubscribe, e-mail: > ><mailto:[EMAIL PROTECTED]> > >MW> For additional commands, e-mail: > ><mailto:[EMAIL PROTECTED]> > > > > > > > >-- > >Best regards, > > Jacob mailto:[EMAIL PROTECTED] > > > > > >-- > >To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> >For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>