- 浏览: 1544040 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (532)
- 软件设计师 (7)
- PSP (5)
- NET MD (9)
- Hibernate (8)
- DIY (51)
- Work (43)
- GAME (24)
- 未分类 (44)
- iPod (6)
- MySQL (39)
- JSP (7)
- 日语能力考试 (36)
- 小说 (4)
- 豆包网 (23)
- 家用电脑 (7)
- DB2 (36)
- C/C++ (18)
- baby (9)
- Linux (13)
- thinkpad (23)
- OA (1)
- UML (6)
- oracle (24)
- 系统集成 (27)
- 脑梗塞 (6)
- 车 (8)
- MainFrame (8)
- Windows 7 (13)
- 手机 (8)
- git (12)
- AHK (2)
- COBOL (2)
- Java (9)
最新评论
-
安静听歌:
... ...
UUID做主键,好还是不好?这是个问题。 -
lehehe:
http://www.haoservice.com/docs/ ...
天气预报 -
lehehe:
[url http://www.haoservice.com/ ...
天气预报 -
liubang201010:
监控TUXEDO 的软件推荐用这个,专业,权威.并能提供报警和 ...
(转载)Tuxedo中间件简介 -
tinkame:
Next[j] =-1 当j=0时;=Max{k|0<k ...
KMP字符串模式匹配详解
JavaTM Logging OverviewLast update Nov 26 2001 |
Documentation Contents |
1.0 Java Logging Overview
1.1 Overview of Control Flow
1.2 Log Levels
1.3 Loggers
1.4 Logging Methods
1.5 Handlers
1.6 Formatters
1.7 The LogManager
1.8 Configuration File
1.9 Default Configuration
1.10 Dynamic Configuration Updates
1.11 Native Methods
1.12 XML DTD
1.13 Unique Message IDs
1.14 Security
1.15 Configuration Management
1.16 Packaging
1.17 Localization
1.18 Remote Access and Serialization
2.0 Examples
2.1 Simple Use
2.2 Changing the Configuration
2.3 Simple Use, Ignoring Global Configuration
2.4 Sample XML Output
3.0 Appendix A: DTD for XMLFormatter Output
1.0 JavaTM Logging Overview
The logging APIs are described in detail in the
1.1 Overview of Control Flow
Applications make logging calls on Logger objects. Loggers are organized in a hierarchical namespace and child Loggers may inherit some logging properties from their parents in the namespace.
Applications make logging calls on Logger objects. These Logger objects allocate LogRecord objects which are passed to Handler objects for publication. Both Loggers and Handlers may use logging Levels and (optionally) Filters to decide if they are interested in a particular LogRecord. When it is necessary to publish a LogRecord externally, a Handler can (optionally) use a Formatter to localize and format the message before publishing it to an I/O stream.
Each Logger keeps track of a set of output Handlers. By default all Loggers also send their output to their parent Logger. But Loggers may also be configured to ignore Handlers higher up the tree.
Some Handlers may direct output to other Handlers. For example, the MemoryHandler maintains an internal ring buffer of LogRecords and on trigger events it publishes its LogRecords through a target Handler. In such cases, any formatting is done by the last Handler in the chain.
The APIs are structured so that calls on the Logger APIs can be cheap when logging is disabled. If logging is disabled for a given log level, then the Logger can make a cheap comparison test and return. If logging is enabled for a given log level, the Logger is still careful to minimize costs before passing the LogRecord into the Handlers. In particular, localization and formatting (which are relatively expensive) are deferred until the Handler requests them. For example, a MemoryHandler can maintain a circular buffer of LogRecords without having to pay formatting costs.
1.2 Log Levels
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).
1.3 Loggers
As stated earlier, client code sends log requests to Logger objects. Each logger keeps track of a log level that it is interested in, and discards log requests that are below this level.
Loggers are normally named entities, using dot-separated names such as "java.awt". The namespace is hierarchical and is managed by the LogManager. The namespace should typically be aligned with the Java packaging namespace, but is not required to follow it slavishly. For example, a Logger called "java.awt" might handle logging requests for classes in the java.awt package, but it might also handle logging for classes in sun.awt that support the client-visible abstractions defined in the java.awt package.
In addition to named Loggers, it is also possible to create anonymous Loggers that don't appear in the shared namespace. See section
Loggers keep track of their parent loggers in the logging namespace. A logger's parent is its nearest extant ancestor in the logging namespace. The root Logger (named "") has no parent. Anonymous loggers are all given the root logger as their parent. Loggers may inherit various attributes from their parents in the logger namespace. In particular, a logger may inherit:
- Logging level. If a Logger's level is set to be null then the Logger will use an effective Level that will be obtained by walking up the parent tree and using the first non-null Level.
- Handlers. By default a Logger will log any output messages to its parent's handlers, and so on recursively up the tree.
- Resource bundle names. If a logger has a null resource bundle name, then it will inherit any resource bundle name defined for its parent, and so on recursively up the tree.
1.4 Logging Methods
The Logger class provides a large set of convenience methods for generating log messages. For convenience, there are methods for each logging level, named after the logging level name. Thus rather than calling "logger.log(Constants.WARNING,..." a developer can simply call the convenience method "logger.warning(..."
There are two different styles of logging methods, to meet the needs of different communities of users.
First, there are methods that take an explicit source class name and source method name. These methods are intended for developers who want to be able to quickly locate the source of any given logging message. An example of this style is:
void warning(String sourceClass, String sourceMethod, String msg);
Second, there are a set of methods that do not take explicit source class or source method names. These are intended for developers who want easy-to-use logging and do not require detailed source information.
void warning(String msg);
For this second set of methods, the Logging framework will make a "best effort" to determine which class and method called into the logging framework and will add this information into the LogRecord. However, it is important to realize that this automatically inferred information may only be approximate. The latest generation of virtual machines perform extensive optimizations when JITing and may entirely remove stack frames, making it impossible to reliably locate the calling class and method.
1.5 Handlers
J2SE provides the following Handlers:
- StreamHandler: A simple handler for writing formatted records to an OutputStream.
- ConsoleHandler: A simple handler for writing formatted records to System.err
- FileHandler: A handler that writes formatted log records either to a single file, or to a set of rotating log files.
- SocketHandler: A handler that writes formatted log records to remote TCP ports.
- MemoryHandler: A handler that buffers log records in memory.
It is fairly straightforward to develop new Handlers. Developers requiring specific functionality can either develop a Handler from scratch or subclass one of the provided Handlers.
1.6 Formatters
J2SE also includes two standard Formatters:- SimpleFormatter: Writes brief "human-readable" summaries of log records.
- XMLFormatter: Writes detailed XML-structured information.
As with Handlers, it is fairly straightforward to develop new Formatters.
1.7 The LogManager
There is a global LogManager object that keeps track of global logging information. This includes:- A hierarchical namespace of named Loggers.
- A set of logging control properties read from the configuration file. See section
There is a single LogManager object that can be retrieved using the static LogManager.getLogManager method. This is created during LogManager initialization, based on a system property. This property allows container applications (such as EJB containers) to substitute their own subclass of LogManager in place of the default class.
1.8 Configuration File
The logging configuration can be initialized using a logging configuration file that will be read at startup. This logging configuration file is in standard java.util.Properties format.
Alternatively, the logging configuration can be initialized by specifying a class that can be used for reading initialization properties. This mechanism allows configuration data to be read from arbitrary sources, such as LDAP. JDBC, etc. See the
There is a small set of global configuration information. This is specified in the description of the LogManager class and includes a list of root-level Handlers to install during startup.
The initial configuration may specify levels for particular loggers. These levels are applied to the named logger and any loggers below it in the naming hierarchy. The levels are applied in the order they are defined in the configuration file.
The initial configuration may contain arbitrary properties for use by Handlers or by subsystems doing logging. By convention these properties should use names starting with the name of the handler class or the name of the main Logger for the subsystem.
For example, the MemoryHandler uses a property "java.util.logging.MemoryHandler.size" to determine the default size for its ring buffer.
1.9 Default Configuration
The default logging configuration that ships with the JRE is only a default, and can be overridden by ISVs, system admins, and end users.
The default configuration makes only limited use of disk space. It doesn't flood the user with information, but does make sure to always capture key failure information.
The default configuration establishes a single handler on the rootr logger for sending output to the console.
1.10 Dynamic Configuration Updates
Programmers can update the logging configuration at run time in a variety of ways:- FileHandlers,MemoryHandlers, and PrintHandlers can all be created with various attributes.
- New Handlers can be added and old ones removed.
- New Loggers can be created and can be supplied with specific Handlers.
- Levels can be set on target Handlers.
1.11 Native Methods
There are no native APIs for logging.Native code that wishes to use the Java Logging mechanisms should make normal JNI calls into the Java Logging APIs.
1.12 XML DTD
The XML DTD used by the XMLFormatter in specified in
The DTD is designed with a "<log></log>" element as the top-level document. Individual log records are then written as "<record></record>" elements.Note that in the event of JVM crashes it may not be possible to cleanly terminate an XMLFormatter stream with the appropriate closing . Therefore tools that are analyzing log records should be prepared to cope with un-terminated streams.
1.13 Unique Message IDs
The Java Logging APIs do not provide any direct support for unique message IDs. Those applications or subsystems requiring unique message IDs should define their own conventions and include the unique IDs in the message strings as appropriate.
1.14 Security
The principal security requirement is that untrusted code should not be able to change the logging configuration. Specifically, if the logging configuration has been set up to log a particular category of information to a particular Handler, then untrusted code should not be able to prevent or disrupt that logging.
A new security permission LoggingPermission is defined to control updates to the logging configuration.
Trusted applications are given the appropriate LoggingPermission so they can call any of the logging configuration APIs. Untrusted applets are a different story. Untrusted applets can create and use named Loggers in the normal way, but they are not allowed to change logging control settings, such as adding or removing handlers, or changing log levels. However, untrusted applets are able to create and use their own "anonymous" loggers, using Logger.getAnonymousLogger. These anonymous Loggers are not registered in the global namespace and their methods are not access-checked, allowing even untrusted code to change their logging control settings.
The logging framework does not attempt to prevent spoofing. The sources of logging calls cannot be determined reliably, so when a LogRecord is published that claims to be from a particular source class and source method, it may be a fabrication. Similarly, formatters such as the XMLFormatter do not attempt to protect themselves against nested log messages inside message strings. This, a spoof LogRecord might contain a spoof set of XML inside its message string to make it look as if there was an additional XML record in the output.
In addition, the logging framework does not attempt to protect itself against denial of service attacks. Any given logging client can flood the logging framework with meaningless messages in an attempt to conceal some important log message.
1.15 Configuration Management
The APIs are structured so that an initial set of configuration information is read as properties from a configuration file. The configuration information may then be changed programatically by calls on the various logging classes and objects.
In addition, there are methods on LogManager that allow the configuration file to be re-read. When this happens, the configuration file values will override any changes that have been made programatically.
1.16 Packaging
All of the logging class are in the java.* part of the namespace, in the java.util.logging package.
1.17 Localization
Log messages may need to be localized.
Each Logger may have a Resource Bundle name associated with it. The corresponding Resource Bundle can be used to map between raw message strings and localized message strings.
Normally localization will be performed by Formatters. As a convenience, the formatter class provides a formatMessage method that provides some basic localization and formatting support.
1.18 Remote Access and Serialization
As with most Java platform APIs, the logging APIs are designed for use inside a single address space. All calls are intended to be local. However, it is expected that some Handlers will want to forward their output to other systems. There are a variety of ways of doing this:
Some Handlers (such as the SocketHandler) may write data to other systems using the XMLFormatter. This provides a simple, standard, inter-change format that can be parsed and processed on a variety of systems.
Some Handlers may wish to pass LogRecord objects over RMI. The LogRecord class is therefore serializable. However there is a problem in how to deal with the LogRecord parameters. Some parameters may not be serializable and other parameters may have been designed to serialize much more state than is required for logging. To avoid these problems the LogRecord class has a custom writeObject method that converts the parameters to strings (using Object.toString()) before writing them out. See the
Most of the logging classes are not intended to be serializable. Both Loggers and Handlers are stateful classes that are tied into a specific virtual machine. In this respect they are analogous to the java.io classes, which are also not serializable.
2.0 Examples
2.1 Simple Use
The following is a small program that performs logging using the default configuration.
This program relies on the root handlers that were established by the LogManager based on the configuration file. It creates its own Logger object and then makes calls to that Logger object to report various events.
package com.wombat;
public class Nose{
// Obtain a suitable logger.
private static Logger logger = Logger.getLogger("com.wombat.nose");
public static void main(String argv[]){
// Log a FINE tracing message
logger.fine("doing stuff");
try{
Wombat.sneeze();
} catch (Error ex){
// Log the error
logger.log(Level.WARNING,"trouble sneezing",ex);
}
logger.fine("done");
}
}
2.2 Changing the Configuration
Here's a small program that dynamically adjusts the logging configuration to send output to a specific file and to get lots of information on wombats:
public static void main(String[] args){
Handler fh = new FileHandler("%t/wombat.log");
Logger.getLogger("").addHandler(fh);
Logger.getLogger("com.wombat").setLevel("com.wombat",Level.FINEST);
...
}
2.3 Simple Use, Ignoring Global Configuration
Here's a small program that sets up it own logging Handler and ignores the global configuration.
package com.wombat;
import java.util.logging.*;
public class Nose {
private static Logger logger = Logger.getLogger("com.wombat.nose");
private static FileHandler fh = new FileHandler("mylog.txt");
public static void main(String argv[]) {
// Send logger output to our FileHandler.
logger.addHandler(fh);
// Request that every detail gets logged.
logger.setLevel(Level.ALL);
// Log a simple INFO message.
logger.info("doing stuff");
try {
Wombat.sneeze();
} catch (Error ex) {
logger.log(Level.WARNING, "trouble sneezing", ex);
}
logger.fine("done");
}
}
2.4 Sample XML Output
Here's a small sample of what some XMLFormatter XML output looks like:
<!---->
<!---->
<log></log>
<record></record>
<date></date>2000-08-23 19:21:05
<millis></millis>967083665789
<sequence></sequence>1256
<logger></logger>kgh.test.fred
<level></level>INFO
<class></class>kgh.test.XMLTest
<method>writeLog</method>
<thread></thread>10
<message></message>Hello world!
3.0 Appendix A: DTD for XMLFormatter Output
<!---->
<!---->
<!---->
<!---->
<!---->
<!---->
<!---->
<!---->
<!---->
<!---->
<!---->
<!---->
<!---->
<!---->
<!---->
<!---->
<!---->
<!---->
<!---->
<!---->
<!---->
<!---->
<!---->
<!---->
<!---->
<!---->
<!---->
<!---->
<!---->
<!---->
<!---->
<!---->
<!---->
<!---->
<!---->
<!---->
<!----><!---->
Copyright ©2002 Sun Microsystems, Inc. All Rights Reserved.
<!---->
Java Software
<script language="JavaScript" src="/js/omi/jsc/s_code_remote.js"></script>
LogRecord API Specification for details. Appendix A. LogManager API Specification for details. 1.8. 1.14. J2SE API Specification. The goal of this document is to provide an overview of key elements.
发表评论
-
(转)SQLデータ型
2011-08-24 18:09 2154https://www.microfocus. ... -
(转)Determining equivalent SQL and COBOL data types
2011-08-24 18:01 1482http://publib.boulder.ibm ... -
(转)grep Programs and Regular expressions
2011-08-10 13:10 1217http://ss64.com/bash/grep-r ... -
(转)find:根据指定条件查找文件
2011-08-10 11:34 1029http://man.ddvip.com/ ... -
(转)[红旗] 手动可以执行,加入crontab 就不行了
2011-07-05 13:07 1805http://bbs.chinaunix.net ... -
(转)Linux——计划任务管理
2011-07-04 15:02 1570http://hi.baidu.com/%BA%CE%B4 ... -
(转)CentOS的计划任务,Crontab安装及使用方法
2011-07-04 15:01 3102http://www.hitsword.org/re ... -
(转)Windows如何压缩tar.gz格式
2011-05-11 10:34 1269http://www.viosem.com/2008/ ... -
(转)日语的文字编码
2011-03-02 10:23 1646http://blog.csdn.net/jackyren ... -
(转)《软件工程的事实与谬论》
2010-11-04 09:57 1685http://book.group.iteye.com ... -
(转)VB6迁移到VB.NET的一些问题汇总
2010-11-03 15:02 1814http://www.cnblogs.com/ols/ar ... -
(转)《张冰Java视频教程》(struts Hibernate spring jsp J2SE)长期更新
2010-07-14 20:51 0http://www.verycd.com/topics/ ... -
(转)使用httpclient4登录百度
2010-02-26 14:45 0http://legend30g-4/article/h ... -
(转)如何一次性从Outlook Express中导出邮件
2010-01-06 13:23 5669http://hi.baidu.com/grape17/b ... -
Top Ten TPC-E by Performance
2009-10-21 14:50 1041http://www.tpc.org/tpc ... -
IBM DB2 UDB 和 SQL Server 2000
2009-10-21 14:49 1357http://www.microsoft.com/chin ... -
TCP/IP環境のPCからメインフレームを使用する
2009-10-16 11:51 0http://cap-l.sakushin-u.ac.jp:8 ... -
JP1名词解释
2009-10-10 15:17 3545http://soft.yesky.com/0/30685 ... -
Java 内存溢出的可能性汇总
2009-02-18 13:42 15691 分配的内存太小, 请使用 JVM 参数设置更大的可用内存 ... -
Java web应用内存溢出 [已结帖,结帖人:pengble]
2009-02-18 13:40 2277加为好友发送私信在线聊天
相关推荐
JavaTM 2 Platform Standard Edition 5.0
《JavaTM 2 Platform Standard Edition 6 API 规范》是Java开发的重要参考资料,它详尽地阐述了Java SE 6平台的核心API,为开发者提供了详细的类库文档,包括类、接口、枚举以及注解等。这个中文版本的CHM文件解决了...
《JavaTM技术手册》(第三版)是一本深入探讨Java编程语言及其相关技术的重要参考资料,旨在为开发者提供全面、详实的Java知识体系。作为Java技术的核心指南,这本书涵盖了从基础语法到高级特性的广泛内容,是提升...
JavaTM 2 Platform Standard Edition 6 API 开发人员文档
本文档概述了 JDK 1.2 所实现的主要安全特征的动机,介绍了新类及其用法,讨论了这种新的体系结构对已有代码的影响,同时给出了将来编写对安全敏感的代码的思路。
### Java 2 Platform Standard Edition 6 (J2SE 6) 概述 #### 平台简介 Java 2 Platform, Standard Edition 6 (J2SE 6) 是一款广泛应用于开发桌面应用、网络应用及服务端应用的软件平台。它提供了丰富的API集合,...
《JavaTM虚拟机规范》第二版是一本由Java虚拟机(JVM)的开发者撰写的权威书籍,深入探讨了Java编程语言的核心——JVM的工作原理。这本书对于理解Java编程的底层机制以及Java在嵌入式环境中的移植至关重要。以下是...
java api的詳細說明。
本文档是 JavaTM Platform Standard Edition 6 的 API 规范。 就是中文帮助文档。 由于等级所限,不能一次传完,这是第一部分,稍后给第二部分,大家可以在我上传的资源里搜索, 第二部分免费,不过要放在一起才能...
JavaTM Platform, Enterprise Edition 6 API Specification 从Oracle官网上搞下来的JavaEE API文档,制作成chm方便查询,保证不添加任何无关内容,纯的
《JavaTM 2 Platform Standard Edition 6》是Java开发领域中的一个重要里程碑,它代表了Java 1.6版本的标准版平台。这个版本的发布对于Java开发者来说,提供了大量的新特性和改进,使得Java编程更加高效、强大且易用...
JavaTM.2.SDK,全称为Java 2 Software Development Kit,是Java编程语言的重要开发环境,由Sun Microsystems(现已被Oracle公司收购)推出。这个SDK包含了编写、编译、调试和运行Java应用程序所需的所有工具和资源。...
Java平台标准版(JavaTM Platform Standard Edition,简称Java SE)6 API规范是Java开发者的重要参考资料,它定义了Java编程语言的核心库,包括类库、接口和异常等,为开发跨平台的应用程序提供了基础。这份规范详细...
JavaTM SE 6 Platform at a Glance
Sun JavaTM Wireless Toolkit for CLDC 的用户手册