3

I created a dynamic web project using IBM Rational Application Developer (RAD). I used java.util.logging as the logging framework. I put the logging.properties in WEB-INF/classes directly.

The problem which I am facing is, the application could not load the logging.properties even I put it in the WEB-INF/classes. I add the following generic JVM arguments in the WebSphere Application Server Administrator's Console

-Djava.util.logging.config.file="logging.properties"

I add the following code snippet in the servlet init method.

Properties prop = System.getProperties();
prop.setProperty("java.util.logging.config.file", "logging.properties");

System.out.println("Is file exists " + file.exists());
try {
    LogManager.getLogManager().readConfiguration();
} catch (IOException ex) {
    ex.printStackTrace();
}

I off the console level debug in logging.properties, so I should not get the logging in console. But currently I am getting the logs in console not in log files which I mentioned in logging.properits.

logging.properties

#------------------------------------------
# Handlers
#-----------------------------------------
handlers=java.util.logging.ConsoleHandler,java.util.logging.FileHandler

# Default global logging level
.level=ALL

# ConsoleHandler
java.util.logging.ConsoleHandler.level=OFF
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter

# FileHandler
java.util.logging.FileHandler.level=FINE

# Naming style for the output file:
java.util.logging.FileHandler.pattern=${SERVER_LOG_ROOT}/nyllogs/loadData.log

# Name of the character set encoding to use
java.util.logging.FileHandler.encoding=UTF8

# Limiting size of output file in bytes:
java.util.logging.FileHandler.limit=25000000

# Number of output files to cycle through
java.util.logging.FileHandler.count=2

# Style of output (Simple or XML):
java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter

Please let me know why the application couldnt pick up the logging.properties file?

Java-Seekar
  • 1,720
  • 5
  • 30
  • 52

2 Answers2

3

In a WebSphere server, the effect of what you are trying to do would be to change the logging configuration not only of the application, but the entire server. Since WebSphere itself uses java.util.logging, this would mean that everything that is logged internally by WebSphere goes to the same file as the application logs. That would be pointless because then you may as well use the standard WebSphere log files (SystemOut.log and trace.log).

In addition, since WebSphere installs its own LogHandler, it is likely that it will forbid usage of the readConfiguration() method.

Andreas Veithen
  • 8,868
  • 3
  • 25
  • 28
0

Read the configuration from an inputstream using readConfiguration(is). Your code sets a property with relative path but the JVM cannot look into it.

Properties prop = System.getProperties();
prop.setProperty("java.util.logging.config.file", "logging.properties");

Calling the readConfiguration() method without arguments only reloads the properties, which may not be loaded since your path is relative.

public void readConfiguration()
                       throws IOException,SecurityException
Reinitialize the logging properties and reread the logging configuration.

Use an absolute path for the property or pass an Inputstream. Here's an example loading the properties from a file and using an InputStream.

Community
  • 1
  • 1
Deepak Bala
  • 11,095
  • 2
  • 38
  • 49
  • Thanks Deepak for your answer. I tried with the both method which you mentioned. I used the Inputstream to load the properties. But no luck. FileInputStream configFile = new FileInputStream("/WEB-INF/classes/logging.properties"); preferences.load(configFile); LogManager.getLogManager().readConfiguration(configFile); Do I need to do any additional configuration in admin console? – Java-Seekar Apr 11 '13 at 06:57
  • hmmm... and there are no exceptions on the console / log files when you try to instantiate the file ? Have you tried stepping through the code with a debugger ? – Deepak Bala Apr 11 '13 at 07:03
  • I am getting the FileNotFound exception. java.io.FileNotFoundException: \WEB-INF\classes\logging.properties (The system cannot find the path specified.) – Java-Seekar Apr 11 '13 at 07:12
  • That is your problem. You should be loading the resource as a stream from the classloader instead. Use [getResourceAsStream](http://docs.oracle.com/javase/6/docs/api/java/lang/ClassLoader.html#getResourceAsStream%28java.lang.String%29) – Deepak Bala Apr 11 '13 at 07:52
  • When I use the getResourceAsStream the property file is loading, but I am getting the log messages in the console only. Not in any log files. – Java-Seekar Apr 11 '13 at 09:30
  • May be that is a RAD specific problem. It should've worked by now. I cant think of anything else. May be log to a known path like '/usr/var/local/logs' instead of using the variables `${}` ? – Deepak Bala Apr 11 '13 at 09:40
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/28020/discussion-between-k-senthuran-and-deepak-bala) – Java-Seekar Apr 11 '13 at 10:10