e385. the quintessential logging program.txt
来自「这里面包含了一百多个JAVA源文件」· 文本 代码 · 共 29 行
TXT
29 行
To log a message, you first need to obtain a Logger object and then use it to log the message. Loggers have names that resemble a fully qualified class name. Typically, log messages generated from a class would use a Logger with the same name as the class.
The logger contains one or more handlers that are responsible for processing the log records. A handler could write to a file or print to a console. Typically, the code that generates log records should not concern itself with where those log records end up. It only needs to decide the name of the logger to use.
This example logs a few messages to a logger. For examples of controlling the destination of the log messages, see e391 Writing Log Records to a Log File and e392 Writing Log Records to Standard Error.
import java.io.*;
import java.util.logging.*;
package com.mycompany;
public class BasicLogging {
public static void main(String[] args) {
// Get a logger; the logger is automatically created if
// it doesn't already exist
Logger logger = Logger.getLogger("com.mycompany.BasicLogging");
// Log a few message at different severity levels
logger.severe("my severe message");
logger.warning("my warning message");
logger.info("my info message");
logger.config("my config message");
logger.fine("my fine message");
logger.finer("my finer message");
logger.finest("my finest message");
}
}
Related Examples
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?