java.util.logging.Logger在哪里存储他们的日志 [英] Where does java.util.logging.Logger store their log

查看:473
本文介绍了java.util.logging.Logger在哪里存储他们的日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个愚蠢的问题,但我对java Logger有点遗失

This might be a stupid question but I am a bit lost with java Logger

private static Logger logger = Logger.getLogger("order.web.OrderManager");
logger.info("Removed order " + id + ".");

我在哪里可以看到日志?此引用来自java.util.logging.Logger库:

Where do I see the log? Also this quote from java.util.logging.Logger library:


在每次日志记录调用中,Logger最初会对请求级别执行廉价检查(例如SEVERE或FINE)对记录器的有效日志级别。如果请求级别低于日志级别,则日志记录调用立即返回。

通过此初始(廉价)测试后,Logger将分配一个LogRecord来描述日志记录消息。然后,它将调用过滤器(如果存在)以更详细地检查是否应该发布记录。如果它通过它然后将LogRecord发布到其输出处理程序。

On each logging call the Logger initially performs a cheap check of the request level (e.g. SEVERE or FINE) against the effective log level of the logger. If the request level is lower than the log level, the logging call returns immediately.
After passing this initial (cheap) test, the Logger will allocate a LogRecord to describe the logging message. It will then call a Filter (if present) to do a more detailed check on whether the record should be published. If that passes it will then publish the LogRecord to its output Handlers.`

这是否意味着如果我有3 请求级别日志:

Does this mean that if I have 3 request level log:

logger.log(Level.FINE, "Something");
logger.log(Level.WARNING, "Something");
logger.log(Level.SEVERE, "Something");

我的日志级别是严重的,我可以看到所有三个日志,如果我的日志级别是警告,那么我看不到SEVERE日志,这是正确的吗?如何设置日志级别

And my log level is SEVERE, I can see all three logs, and if my log level is WARNING, then I can't see SEVERE log, is that correct? And how do I set the log level?

推荐答案


我在哪里可以看到日志?

Where do I see the log?

在日志文件或标准输出中,具体取决于您的实际日志处理程序配置。这可以通过属性文件或直接通过日志API进行设置。

In a log file or standard output, depending on your actual log handler configuration. This can be set via a property file or directly via the logging API.


这是否意味着如果我有3个请求级别日志.. 。

Does this mean that if I have 3 request level log...

SEVERE 是最重要的(最高优先级)和 FINE 是示例中显示的3中最不重要的消息类型。因此,如果您的日志级别为 SEVERE ,则只会记录 SEVERE 消息。如果level是 FINE ,则会记录所有3条消息。

SEVERE is the most important (highest priority) and FINE is the least important message type of the 3 shown in your example. So if your log level is SEVERE, only the SEVERE messages get logged. If level is FINE, all 3 messages get logged.

这在实际生产环境中非常有用可能只想记录错误和可能的警告(希望 - 很少见,但你想知道它们),所以你可以将日志级别设置为警告。但是,在您的开发环境中,例如,调试问题时,您希望查看日志中的所有信息,即使它会创建大量日志数据并降低应用程序速度。因此,您将日志级别设置为 FINE FINEST

This is very useful when in real production environment, you may want to log only the errors and possibly warnings (which are - hopefully - fairly rare, but you want to know about them), so you can set log level to WARNING. However, in your development environment, when e.g. debugging a problem, you want to see all information in the logs, even though it creates a large amount of log data and slows down the application. So you set log level to FINE or FINEST.

这是一个很好的 Java日志介绍

更新:上述页面中的一个简单示例,用于配置记录器以目录登录文件

Update: a simple example from the above page to configure the logger to log to a file at level FINEST:

Handler fh = new FileHandler("%t/wombat.log");
Logger.getLogger("").addHandler(fh);
Logger.getLogger("com.wombat").setLevel(Level.FINEST);

要登录控制台,请替换 FileHandler 上面带有 ConsoleHandler

To log to the console, replace the FileHandler above with a ConsoleHandler:

Handler ch = new ConsoleHandler();
Logger.getLogger("").addHandler(ch);

这只是一个例子 - 在真实的应用程序中,最好通过一个配置日志记录配置属性文件。

This is just an example though - in a real app, it is preferable to configure the logging via a config property file.

这篇关于java.util.logging.Logger在哪里存储他们的日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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