为什么 java 日志记录创建了 .lck 文件但没有删除

发布于 2024-11-02 18:54:02 字数 2171 浏览 2 评论 0原文

我正在尝试使用 java.util.logging 实现应用程序级记录器(部署在 weblogic 中的 webapps)。

我从 apache JULI 日志系统中获取了 ClassLoaderLogManager,因为它已经实现了应用程序级别日志记录。

这就是我的 servlet 代码 (SimpleServlet.java) 的样子:

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();  

并且我在 java_home/jre/lib 中有logging.properties 文件,如下所示

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

所以当我运行 web 应用程序时 - 并且当我访问webapp 我希望创建 java_0.log、java_1.log(日志文件轮换)等。但我也看到 java0.log.lck, java1.log.lck 。

日志文件仅按预期显示 SEVERE 级别日志。

为什么会出现这种情况?如果我在 java 代码端创建了一个处理程序,关闭该处理程序将解决该问题。买了不是这里处理的吗?

或者是因为我在使用 org.apache.juli.ClassLoaderLogManager 时使用 java.util.logging.FileHandler 而不是 org.apache.juli.FileHandler ??

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
??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

薯片软お妹 2024-11-09 18:54:02

当 FileHandler 打开时,您应该会看到锁定文件。如果您看到它们在 VM 退出后徘徊,那么这是因为 FileHandler 未关闭,VM 在处理程序关闭挂钩运行时停止或崩溃,或者在尝试删除它们时发生 I/O 异常。

您可能会遇到 JDK-8060132 在logging.properties中的抽象节点上配置的处理程序并不总是正确的已关闭。相关:JDK-6274920:JDK 记录器拥有对 java.util.logging.Logger 实例的强引用。

查看配置,您在根记录器上安装了一个 FileHandler,在 SimpleServlet 上安装了一个 FileHandler 。由于 ClassLoaderLogManager 没有以 JVM 全局方式使用,因此安装的默认 LogManager 会在启动本地 ClassLoaderLogManager 之前创建 FileHandler。从您拥有的 java_home/jre/lib comfig 中删除 FileHandler 条目,并使用 ClassLoaderLogManager.readConfiguration 方法加载 web 应用程序本地配置。

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.

You could be running into JDK-8060132 Handlers configured on abstract nodes in logging.properties are not always properly closed. Related: JDK-6274920: JDK logger holds strong reference to java.util.logging.Logger instances.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文