I am trying to implement an application level logger (webapps deployed in weblogic) - using java.util.logging .
I took the ClassLoaderLogManager from apache JULI logging system since it already implements application level logging.
So this is how my servlet code (SimpleServlet.java) looks like :
ClassLoaderLogManager ClassLoaderLogManager = new ClassLoaderLogManager () ;
String nameoflogger = SimpleServlet.class.getName() ;
boolean status = ClassLoaderLogManager .addLogger(nameoflogger);
if(status)
{
Logger logger = ClassLoaderLogManager .getLogger(nameoflogger);
logger.log(Level.FINEST, "testing SimpleServlet FINEST");
logger.log(Level.INFO, "testing SimpleServlet INFO");
logger.log(Level.SEVERE, "testing SimpleServlet SEVERE");
}
ClassLoaderLogManager .reset();
And i have the logging.properties file in java_home/jre/lib as follows
handlers= java.util.logging.FileHandler
#.level= INFO
# default file output is in user's home directory.
java.util.logging.FileHandler.pattern = %h/java_%g.log
java.util.logging.FileHandler.limit = 200
java.util.logging.FileHandler.count = 10
java.util.logging.FileHandler.append = true
java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter
# Limit the message that are printed on the console to INFO and above.
#java.util.logging.ConsoleHandler.level = INFO
#java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
package8.SimpleServlet.handler = java.util.logging.FileHandler
############################################################
# Facility specific properties.
# Provides extra control for each logger.
############################################################
# For example, set the com.xyz.foo logger to only log SEVERE
# messages:
package8.SimpleServlet.level = SEVERE
So when i run the webapp - and as i access the webapp i expect java_0.log, java_1.log (log file rotation)- etc to be created. But am also seeing java0.log.lck, java1.log.lck .
The logs files are only showing SEVERE level logs as expected.
Why does this happen ? If i has creating a handler on the java code side , closing the handler would solve the issue . Buy y isnt it handled here ?
Or is it because am using am using java.util.logging.FileHandler and not org.apache.juli.FileHandler while using org.apache.juli.ClassLoaderLogManager
??
解决方案
You should expect to see lock files when the FileHandler is open. If you see them linger after the VM exits, then it is because the The FileHandler was not closed, the VM was halted or crashed while the handler shutdown hook was running, or an I/O exception took place while trying to remove them.
Looking at the config, you have a FileHandler installed on the root logger and a FileHandler installed on the SimpleServlet. Since the ClassLoaderLogManager is not being used in a JVM global way, the installed default LogManager is creating the FileHandlers before you startup your local ClassLoaderLogManager. Remove the FileHandler entries from the java_home/jre/lib comfig you have and use the ClassLoaderLogManager.readConfiguration methods to load the webapp local configuration.