如何使用JDK Logging手动滚动日志文件 [英] How to manually roll over the logfile with JDK Logging

查看:121
本文介绍了如何使用JDK Logging手动滚动日志文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,它使用JDK Logging和logging.properties文件,该文件通过java.util.logging.FileHandler.count配置一些较旧的日志文件。

I have an application which uses JDK Logging with a logging.properties file which configures a number of older log-file via java.util.logging.FileHandler.count.

在应用程序的某些点上,我想触发日志文件的手动翻转以启动新的日志文件,例如:在计划的活动开始之前。

At certain points in the application I would like to trigger a manual rollover of the logfile to have a new logfile started, e.g. before a scheduled activity starts.

这是否可以通过JDK Logging实现?

Is this possible with JDK Logging?

在Log4j中我使用以下内容,但是在这种情况下我想使用JDK Logging!

In Log4j I am using the following, however in this case I would like to use JDK Logging!

Logger logger = Logger.getRootLogger();
Enumeration<Object> appenders = logger.getAllAppenders();
while(appenders.hasMoreElements()) {
    Object obj = appenders.nextElement();
    if(obj instanceof RollingFileAppender) {
        ((RollingFileAppender)obj).rollOver();
    }
}


推荐答案

你必须编写自己的处理程序才能使轮换工作。像 JBoss Log Manager 这样的东西适用于JDK日志记录,只是替换了logmanger部分。它已经有一些不同的旋转处理程序

You would have to write your own handler in order to get a rotation to work. Something like JBoss Log Manager works with JDK logging and just replaces the logmanger parts. It already has a few different rotating handlers.

这篇关于如何使用JDK Logging手动滚动日志文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆