public class SimpleFormatter extends Formatter
LogRecord
小结。通常的摘要将是1或2行。
Configuration:的SimpleFormatter
是在java.util.logging.SimpleFormatter.format
属性format日志消息中指定的format string初始化。此属性可以在logging properties配置文件或作为一个系统属性定义。如果将此属性设置为日志属性和系统属性,则将使用系统属性中指定的格式字符串。如果这个属性没有定义或给定的格式字符串的illegal,默认的格式是具体实施。
Formatter
Constructor and Description |
---|
SimpleFormatter() |
public String format(LogRecord record)
格式可以通过在 java.util.logging.SimpleFormatter.format
属性指定format string定制。给定的LogRecord
将被格式化为如果通过调用:
String.format
(格式、日期、来源、记录仪、水平、消息,抛出);
参数:
format
在java.util.logging.SimpleFormatter.format
财产或默认的格式指定的java.util.Formatter
格式字符串。date
-代表该日志记录event time Date
对象。source
-一个字符串代表来电,如果可用;否则,日志的名字。logger
-日志的名字。level
- log level。message
-格式化日志消息从Formatter.formatMessage(LogRecord)
方法返回。它采用java.text
格式和不使用java.util.Formatter format
论点。thrown
-字符串代表一个换行符,日志记录和回溯的开始相关的throwable如果任何;否则,空字符串。一些例子:
格式
java.util.logging.SimpleFormatter.format="%4$s: %5$s [%1$tc]%n"
此印1线的日志级别(4$
),日志消息(5$
)和时间戳(1$
)在方括号。
警告:警告消息[ 3月22日星期二13:11:31 PDT 2011 ]
java.util.logging.SimpleFormatter.format="%1$tc %2$s%n%4$s: %5$s%6$s%n"
这个打印2行,第一行包含时间戳(1$
)和源(2$
);第二行包括日志级别(4$
)和日志消息(5$
)跟着Throwable及其回溯(6$
),如果任何:
3月22日星期二13:11:31 PDT 2011 MyClass致命严重:几个异常的消息java.lang.illegalargumentexception:无效的参数在MyClass。醪(java中:9)在MyClass。紧缩(java中:6)在MyClass。主要(java中:3)
java.util.logging.SimpleFormatter.format="%1$tb %1$td, %1$tY %1$tl:%1$tM:%1$tS %1$Tp %2$s%n%4$s: %5$s%n"
这个打印2行类似于上面的例子不同的日期和时间格式和不打印错误和回溯:
2011年3月22日下午1:11:31 MyClass致命严重:几个异常的消息
这种方法也可以在子类中重写。这是推荐使用的方法Formatter.formatMessage(java.util.logging.LogRecord)
方便定位和格式的报文字段。
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.