提供Java TM 2平台核心日志记录工具的类和接口。 日志API的中心目标是支持在客户站点维护和维护软件。
- Problem diagnosis by end users and system administrators. This consists of simple logging of common problems that can be fixed or tracked locally, such as running out of resources, security failures, and simple configuration errors.
- Problem diagnosis by field service engineers. The logging information used by field service engineers may be considerably more complex and verbose than that required by system administrators. Typically such information will require extra logging within particular subsystems.
- Problem diagnosis by the development organization. When a problem occurs in the field, it may be necessary to return the captured logging information to the original development team for diagnosis. This logging information may be extremely detailed and fairly inscrutable. Such information might include detailed tracing on the internal execution of particular subsystems.
- Problem diagnosis by developers. The Logging APIs may also be used to help debug an application under development. This may include logging information generated by the target application as well as logging information generated by lower-level libraries. Note however that while this use is perfectly reasonable, the logging APIs are not intended to replace the normal debugging and profiling tools that may already exist in the development environment.
The key elements of this package include:
- Logger: The main entity on which applications make logging calls. A Logger object is used to log messages for a specific system or application component.
- LogRecord: Used to pass logging requests between the logging framework and individual log handlers.
- Handler: Exports LogRecord objects to a variety of destinations including memory, output streams, consoles, files, and sockets. A variety of Handler subclasses exist for this purpose. Additional Handlers may be developed by third parties and delivered on top of the core platform.
- Level: Defines a set of standard logging levels that can be used to control logging output. Programs can be configured to output logging for some levels while ignoring output for others.
- Filter: Provides fine-grained control over what gets logged, beyond the control provided by log levels. The logging APIs support a general-purpose filter mechanism that allows application code to attach arbitrary filters to control logging output.
- Formatter: Provides support for formatting LogRecord objects. This package includes two formatters, SimpleFormatter and XMLFormatter, for formatting log records in plain text or XML respectively. As with Handlers, additional Formatters may be developed by third parties.
日志记录API提供静态和动态配置控制。 静态控制使现场服务人员能够设置特定配置，然后使用新的日志记录设置重新启动应用程序。 动态控制允许更新当前正在运行的程序中的日志记录配置。 这些API还允许为系统的不同功能区域启用或禁用日志记录。 例如，现场服务工程师可能有兴趣跟踪所有的AWT事件，但可能对套接字事件或内存管理没有兴趣。
有关控制流程的概述，请参阅 Java Logging Overview 。