如何规范记录指令产生的打印输出量随着时间的推移而产生? [英] How to regulate the amount of printouts generated by a logging instruction produces over time?

查看:95
本文介绍了如何规范记录指令产生的打印输出量随着时间的推移而产生?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Y秒内将程序日志打印输出限制为最多X个打印输出?

How can I limit a program log printouts to a maximum of X printouts within Y seconds?

使用java.util.logging编程服务器端,我的代码有一个许多信息,警告和错误陈述,如:

Programming server side with java.util.logging, my code has a lot of info, warning, and error statements like:

s_logger.logp(Level.WARNING, myClassName, myMethodName, "msg.code.in.properties.file");

一方面,我想看到上面打印的警告信息到了STDOUT,因为它表明出现了问题,特别是在调查生产中的问题时,但另一方面,印刷了很多在短时间内讲述相同故事的线条,没有附加价值,反而达到了性能并介绍滚动盲。

On the one hand, I do want to see the warning message above printed to the STDOUT, since it serves an indication that something went wrong, especially when investigating problems in production, but on the other hand, printing numerous lines that tells the same story over a short period of time, has no added value but instead hit performance and introduces scrolling blindness.

我正在寻找的是一种机制/ API,可以在y秒内将每个消息代码的打印输出调整为不超过x条消息。例如,在一分钟内,我不想生成和写入超过10个类型的消息:事务超时。

What I'm looking for is a mechanism/API that could regulate the printouts to no more than x messages, per message code, during y seconds. For example, over the course of a minute, I don't want to generate and write to the log more than 10 messages of the type: "transaction timed out".

我很高兴API或库参考,任​​何人?

I'd be happy for a API or a library reference, Anyone?

推荐答案

如果你想使用标准的日志记录库/机制,你可以在标准记录器周围生成你自己的包装器,它将检查你是否记录的条件,并且仅在条件下将信息传递给记录机制很满意。

if you want to use standard logging library/mechanism, you may produce your own wrapper around the standard logger which will check for your conditions whether to log or not, and pass the info down to the logging mechanism only if conditions are satisfied.

或者你可以编写自己的(简单的,或许不是)记录器:)

or you can write your own (simple, or maybe not) logger :)

这篇关于如何规范记录指令产生的打印输出量随着时间的推移而产生?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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