Logging configuration file w/ web start

T

Tobias Besch

How do I specify a logging configuration file with Java Web Start?

When I call my Java application vom the command line,
I specify the logging configuration file in the following way:

java -Djava.util.logging.config.file=myLogging.properties -classpath
my.jar -jar my.jar

What is the proper way to specify a logging configuration file for
Java Web Start?

Cheers,
Tobias
 
O

Oscar kind

What is the proper way to specify a logging configuration file for
Java Web Start?

I generally prefer to locate the log4j configuration file myself, and feed
it to log4j. This has the advantage that the file can be picked up from
anywhere in the classpath. Even from the jar file that also contains your
application.

The advantage is that it always works.

The disadvantage is that is difficult to customize. For the applications I
write, this is not a problem. YMMV

java -Djava.util.logging.config.file=myLogging.properties -classpath
my.jar -jar my.jar

A side note: if you specify the -jar option, both the -cp and -classpath
options are ignored. Use the Class-Path header in the manifest to extend
the classpath.
 
T

Tobias Besch

Hi Oscar,
thank you for your answer!

Oscar kind said:
I generally prefer to locate the log4j configuration file myself, and
feed it to log4j...

Could you please tell me how you do this?

BTW: I don't use log4j. I use java.util.logging.

Cheers,
Tobias
 
O

Oscar kind

Tobias Besch said:
Oscar kind wrote in news:[email protected]:

Could you please tell me how you do this?

BTW: I don't use log4j. I use java.util.logging.

I place log4j.properties in the default package, i.e. in the root of
the .jar file. I also use the following LogFactory (package statement
stripped):

===== begin code =====
mport org.apache.commons.logging.Log;
import org.apache.commons.logging.impl.Log4JLogger;
import org.apache.commons.logging.impl.LogFactoryImpl;
import org.apache.log4j.PropertyConfigurator;


/**
* @author <a href="mailto:eek:[email protected]">Oscar Kind</a>
* @version $Id: LogFactory.java,v 1.1 2004/10/04 14:27:54 oscar Exp $
*/
public class LogFactory
{
/**
* Logging factory.
*/
private static final org.apache.commons.logging.LogFactory LOG_FACTORY =
new LogFactoryImpl();

/**
* Static initializer that initializes the LOG_FACTORY above.
*/
static
{
LOG_FACTORY.setAttribute(
LogFactoryImpl.LOG_PROPERTY,
Log4JLogger.class.getName());
PropertyConfigurator.configure(
LogFactory.class.getResource("/log4j.properties"));
}


/**
* Private, empty constructor: this is a utility class.
*/
private LogFactory()
{
// Empty
}


/**
* Get a logger for the specified class.
*
* @param clazz the class to get a logger for.
* @return a logger
*/
public static Log getLogger(Class clazz)
{
return LOG_FACTORY.getInstance(clazz);
}
}
====== end code ======
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top