简体   繁体   English

java.util.logging.Logger在哪里存储他们的日志

[英]Where does java.util.logging.Logger store their log

This might be a stupid question but I am a bit lost with java Logger 这可能是一个愚蠢的问题,但我有点迷失java Logger

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

Where do I see the log? 我在哪里可以看到日志? Also this quote from java.util.logging.Logger library: 此引用来自java.util.logging.Logger库:

On each logging call the Logger initially performs a cheap check of the request level (eg SEVERE or FINE) against the effective log level of the logger. 在每次日志记录调用时,Logger最初会根据记录器的有效日志级别对请求级别(例如SEVERE或FINE)执行廉价检查。 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. 在通过此初始(廉价)测试后,Logger将分配一个LogRecord来描述日志消息。 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.` 如果通过它,则将LogRecord发布到其输出Handlers

Does this mean that if I have 3 request level log: 这是否意味着如果我有3个request level日志:

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

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? 我的log level是SEVERE,我可以看到所有三个日志,如果我的log level是WARNING,那么我看不到SEVERE日志,这是正确的吗? And how do I set the log level ? 我如何设置log level

Where do I see the log? 我在哪里可以看到日志?

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. 这可以通过属性文件设置,也可以直接通过日志记录API设置。

Does this mean that if I have 3 request level log... 这是否意味着如果我有3个请求级别日志...

SEVERE is the most important (highest priority) and FINE is the least important message type of the 3 shown in your example. SEVERE是最重要的(最高优先级), FINE是示例中显示的3中最不重要的消息类型。 So if your log level is SEVERE , only the SEVERE messages get logged. 因此,如果您的日志级别为SEVERE ,则仅记录SEVERE消息。 If level is FINE , all 3 messages get logged. 如果level为FINE ,则会记录所有3条消息。

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 . 这在实际生产环境中非常有用,您可能只想记录错误和可能的警告(希望 - 非常罕见,但您想了解它们),因此您可以将日志级别设置为WARNING However, in your development environment, when eg 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 . 因此,您将日志级别设置为FINEFINEST

Here is a good introduction to Java Logging . 以下是Java Logging的一个很好的介绍

Update: a simple example from the above page to configure the logger to log to a file at level FINEST : 更新:上面一页中的一个简单示例,用于将记录器配置为以FINEST级别登录文件:

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

To log to the console, replace the FileHandler above with a ConsoleHandler : 要登录控制台,请使用ConsoleHandler替换上面的FileHandler

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

The Java TM Logging Overview is quite interesting to answer all your questions on the Java Logger : Java TM Logging Overview非常有趣,可以回答Java Logger上的所有问题:

记录概述

You will see your log where the Handler (s) associated with your Logger will generate said Log (in a Console , or in a Stream ...). 您将看到与Logger相关联的Handler将生成所述日志的日志(在ConsoleStream ......)。
The default configuration establishes a single handler on the root logger for sending output to the console. 默认配置在根记录器上建立单个处理程序,用于将输出发送到控制台。

Log Level : 日志级别

Each log message has an associated log Level. 每条日志消息都有一个关联的日志级别。 The Level gives a rough guide to the importance and urgency of a log message. 该级别粗略指导了日志消息的重要性和紧迫性。 Log level objects encapsulate an integer value, with higher values indicating higher priorities. 日志级别对象封装整数值,值越高表示优先级越高。

The Level class defines seven standard log levels, ranging from FINEST (the lowest priority, with the lowest value) to SEVERE ( the highest priority, with the highest value ). Level类定义了七个标准日志级别,范围从FINEST (最低优先级,最低值)到SEVERE最高优先级,具有最高值 )。

Where it goes is dependent on your configuration. 它的位置取决于您的配置。 There are details about this in the API docs. API文档中有关于此的详细信息。 The log level is the exact reverse of what you said. 日志级别与您所说的完全相反。 If you have a configuration of FINE , everything that is FINE, WARNING, SEVERE will show up, but if you have it set to SEVERE then only those will come up. 如果你有FINE的配置,那么FINE, WARNING, SEVERE所有东西都会出现,但如果你把它设置为SEVERE那么只有那些会出现。

In general you should use FINE while debugging and switch to SEVERE when it is in a production environment. 通常,您应该在调试时使用FINE ,并在生产环境中切换到SEVERE

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM