At 05:33 PM 6/3/2004 -0400, you wrote:
Hi:

    I am writing a Java based library for which I am using the log4j
package (version 1.2.8)



    I am new to log4j. I am confused about the following points:

    a) Are there any special things we need to worry about
configuration.

       Currently, I am considering configuration from a properties file
using the PropertyConfigurator class when the library

initializes.

Sure. You can use a properties file or XML file

 I am planning to include a logging .properties file
within my .jar file for the library.

Bad idea. Logging is for your users, not for you (unless you are *using* your library, of course)


       The case I am considering I when users (read as applications) of
my library may also be using log4j.

Exactly! You can't know what your users want to log and if you provide a default log4j.properties file in the classpath, then you may end up overriding a users own properties file causing the user excessive confusion as to why Log4j isn't logging the way they have it configured.


  I am not sure if I

       use PropertyConfigurator class without resetting logging
configuration of a user in that case.

This is an even worse idea than providing a properties file which *might* override a users. In this case, you are programmatically configuring Log4j and will almost certainly override a users logging configuration, again, causing excessive confusion for the user.


If you want a compromise, you could maybe provide a default log4j.properties file, but don't put it in the root of the jar where Log4j is looking for it. Then provide a utility class with a static method such as Log4jUtility.configureMyLibrary() which the user can call, if desired. configureMyLibrary() would load up your properties file and programmatically configure Log4j. Since this will be used only with the user's clear intent, then there should be no confusion, keeping everyone happy.

       Specifically, I would like all loggers within my library to be at
least at the WARN level. Is there a way I can ensure that

even if I am writing a library.

The simple truth is that you shouldn't force your own concept of what you want logged upon your users. If users want to see logging from your app, they can specify your package to be logged (as long as you stick to the standard naming conventions for loggers, eg.... "com.mypackage.MyClass").




   b) For RollingFileAppender, is there a nice way to specify location
of log file without hard-coding the path. I am interested in knowing
what other library writers do in such cases.

Reference the name of a system property and make sure to provide that system property either programmatically (before any configuration of Log4j happens) or via the command line such as:


java -Dlog_location=/path/to/log/directory MyClass

In the config file, have something like...

${log_location}/mylog.log



Hope the user community can help me with these questions.

I hope I helped!

Jake



regards

Somesh Marepalli




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to