Java Logging: Overview

Table of Contents

In this text I will try to give you an overview of the java.util.logging API. Hopefully it will be easier to understand the individual components once you understand the big picture. Many of the concepts described here are also covered in more details in subsequent texts.

Here is an overview diagram of how the Java Logging API works:

An overview of the core components in the Java Logging API

All logging is done via a Logger instance. Loggers gather the data to be logged into a LogRecord. TheLogRecord is then forwarded to a Handler. The Handler determines what to do with the LogRecord. For instance, the LogRecord can be written to disk, or sent over the network to a surveillance system.

Both Logger‘s and Handler‘s can pass the LogRecord through a Filter which determines whether theLogRecord should be forwarded or not.

Handler can also use a Formatter to format the LogRecord as a string before it is sent to the external disk or system.

Log Level

Whenever a message is logged, this message is logged with a certain log level. The level is an integer which determines how important the message is. The higher the number (level) is, the more important the message is.

Logger can have a minimum log level set on it, which determines if the message is forwarded to a Handler or not. This is not a Filter, even though it has the same effect. For instance, all messages below a certain level can be suppressed.

Logger Hierarchy

The Logger instances are organized into a hierarchy. A Logger further down in the hierarchy will forward messages logged to it, to its ancestors in the hierarchy. Thus, log levels and messages can be filtered or switched on and off for entire branches of the Logger hierarchy at a time.

LogManager

The LogManager is a component that is not displayed in the diagram at the top of this text. The LogManagerholds the Logger hierarchy, and also a global logging configuration, which can be read from a file. TheLogManager is also covered in more detail in its own text.

时间: 2024-12-28 10:10:46

Java Logging: Overview的相关文章

Java Logging API - Tutorial

Java Logging This article describes how to use the Logging API in Java programs. It includes an example for creating an HTML logger. Table of Contents 1. Overview 1.1. Logging 1.2. Logging in Java 1.3. Create a logger 1.4. Level 1.5. Handler 1.6. For

Blobstore Java API overview

Blobstore API允许你的应用程序使用(serve)叫做Blobs的数据对象.这种数据对象比Datastore服务所允许的对象的尺寸大得多.Blobs能有效地为大文件比如视频.图片提供服务,允许用户上传大数据文件.通过HTTP请求上传一个文件来创建Blobs.通常,你的应用程序通过向用户呈现一个表格(form)和一个文件上传区域(a file upload field)来实现.当这个表格被提交的时候,Blobstore会从文件的内容来创建一个Blob,并且返回一个指向blob的叫做blo

Java Logging: Formatters

The Handler's in the Java Logging API use a java.util.logging.Formatter to format theLogRecord's before writing it to an external system. Java comes with two built-in Formatter's (subclasses of Formatter): SimpleFormatter XMLFormatter The various Han

Java Logging: Logger

Table of Contents Logging Messages The log() Methods The logp() Methods The logrb() Methods The Last Log Methods Adding and Removing Handlers Setting a Log Filter Setting the Log Level Parent Logger Additional Methods The java.util.Logger class is th

Java Logging: Configuration

Table of Contents Configuration Class Configuration File The Java Logging API can be configured in two ways: Via a configuration class. Via a configuration file. The initialization of the configuration is taken care of by the java.util.logging.LogMan

Java NIO Overview

Java Nio 1 Java NIO Tutorial 2 Java NIO Overview 3 Java NIO Channel 4 Java NIO Buffer 5 Java NIO Scatter / Gather 6 Java NIO Channel to Channel Transfers 7 Java NIO Selector 8 Java NIO FileChannel 9 Java NIO SocketChannel 10 Java NIO ServerSocketChan

Java Logging: Handlers

Table of Contents Handlers and Formatters Built-in Handlers ConsoleHandler FileHandler File Name Pattern StreamHandler SocketHandler MemoryHandler A Handler is a component that takes care of the actual logging to the outside world. You can add one or

Java Logging: Logger Hierarchy

Table of Contents Filters and Handlers in the Logger Hierarchy Log Levels of Loggers in the Hierarchy The Logger's used in your application are typically organized into a hierarchy, as mentioned elsewhere in this tutorial. This text will take a close

Java Logging: Log Levels

Table of Contents Filtering Messages When a message is logged via a Logger it is logged with a certain log level. The built-in log levels are: SEVERE WARNING INFO CONFIG FINE FINER FINEST The log level is represented by the class java.util.logging.Le