java.util.logging:如何抑制日期行 [英] java.util.logging: how to suppress date line

查看:31
本文介绍了java.util.logging:如何抑制日期行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 java.util.logging 中使用默认记录器时,我试图在日志记录期间抑制日期行的输出.例如,这是一个典型的输出:

<前>2010 年 6 月 1 日上午 10:18:12 gamma.utility.application 信息
信息:ping:db-time=2010-06-01 10:18:12.0,local-time=20100601t101812,持续时间=180000
2010 年 6 月 1 日上午 10:21:12 gamma.utility.application 信息
信息:ping:db-time=2010-06-01 10:21:12.0,local-time=20100601t102112,持续时间=180000

我想去掉 Jun 1, 2010... 行,它们只会使我的日志输出变得混乱.我该怎么做?

解决方案

问题是由父日志中的处理程序引起的.解决方案是从父日志中删除所有处理程序,然后添加自己的自定义处理程序.此代码从父日志中删除处理程序:

<前>for(Handler iHandler:log.getParent().getHandlers()){log.getParent().removeHandler(iHandler);}

I'm trying to suppress output of the date line durinng logging when using the default logger in java.util.logging. For example, here is a typical output:

Jun 1, 2010 10:18:12 AM gamma.utility.application info

INFO: ping: db-time=2010-06-01 10:18:12.0, local-time=20100601t101812, duration=180000
Jun 1, 2010 10:21:12 AM gamma.utility.application info
INFO: ping: db-time=2010-06-01 10:21:12.0, local-time=20100601t102112, duration=180000

I would like to get rid of the Jun 1, 2010... lines, they just clutter my log output. How can I do this?

解决方案

The problem is caused by a handler in the parent log. The solution is to remove all handlers from the parent log, and then add own custom handler. This code removes handlers from the parent log:

      for(Handler iHandler:log.getParent().getHandlers())
        {
        log.getParent().removeHandler(iHandler);
        }

这篇关于java.util.logging:如何抑制日期行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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