- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我想答案可能会有所不同,具体取决于所使用的处理程序,但假设使用了 ConsoleHandler 并使用了默认的 SimpleFormatter。传递给 SimpleFormatter.format() 的每个参数的数量、类型和可能的含义/语义是什么?
我在另一个 SO 问题中找到了这个字符串:
"%1\$tY-%1\$tm-%1\$td %1\$tH:%1\$tM:%1\$tS.%1\$tL %4\$s %2\$s %5\$s%6\$s%n"
(为 Groovy 添加了反斜杠)
注意缺少的 %3
,那么这个参数是什么?还有 %7
、%8
等等……它们是什么?
我想 %1
是当前时间,%4
是日志级别和其他几个...我正在寻找完整的参数列表和他们的意义/值(value)。
最佳答案
来自 http://docs.oracle.com/javase/7/docs/api/java/util/logging/SimpleFormatter.html
where the arguments are:
1 format - the java.util.Formatter format string specified in the java.util.logging.SimpleFormatter.format property or the default format.
2 date - a Date object representing event time of the log record.
3 source - a string representing the caller, if available; otherwise, the logger's name.
4 logger - the logger's name.
5 level - the log level.
6 message - the formatted log message returned from the Formatter.formatMessage(LogRecord) method. It uses java.text formatting and does not use the java.util.Formatter format argument.
7 thrown - a string representing the throwable associated with the log record and its backtrace beginning with a newline character, if any; otherwise, an empty string.
由于第一个参数是格式字符串,其余参数从索引 1 开始(日期在前):
in the format string:
1 date - a Date object representing event time of the log record.
2 source - a string representing the caller, if available; otherwise, the logger's name.
3 logger - the logger's name.
4 level - the log level.
5 message - the formatted log message returned from the Formatter.formatMessage(LogRecord) method. It uses java.text formatting and does not use the java.util.Formatter format argument.
6 thrown - a string representing the throwable associated with the log record and its backtrace beginning with a newline character, if any; otherwise, an empty string.
(我无法相信我在发布到 SO 之前的初始搜索中找不到它 :-)
关于java - 使用默认 Java Logging API 的 SimpleFormatter 的默认参数是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22261246/
我在 GlassFish 4 上使用 java.util.logging。 我正在定义我自己的类,通过定义系统属性来初始化 LogManager:-Djava.util.logging.config.
我正在向我的程序添加一个记录器,在网上冲浪时,我向我的代码添加一个非常简单的记录器,具有基本的两行定义: private static final Logger LOG = Logger.getLog
我试图以 SimpleFormatter 格式限制源参数的长度,以便在 Tomcat 8 中使用。 我读过 SimpleFormatter doc和 Formatter syntax doc虽然我不会
我正在使用 SimpleFormatter 编写日志文件。这些是用 XML 而不是纯文本编写的。我找到的将其写为纯文本的答案都只说使用简单的格式化程序(例如 https://stackoverflow
这个问题不太可能帮助任何 future 的访问者;它只与一个小的地理区域、一个特定的时间点或一个非常狭窄的情况有关,这些情况并不普遍适用于互联网的全局受众。为了帮助使这个问题更广泛地适用,visit
我正在使用 JUL 进行日志记录,我有一个属性文件。我想在我的日志文件中以毫秒为单位记录日期时间。 这是我的属性(property): java.util.logging.SimpleFormatte
我想改变我的日志的外观(java.util.logging.Logger),我发现了这个: System.setProperty("java.util.logging.SimpleFormatter.
我想答案可能会有所不同,具体取决于所使用的处理程序,但假设使用了 ConsoleHandler 并使用了默认的 SimpleFormatter。传递给 SimpleFormatter.format()
我在我的 Tomcat 安装上部署了几个 Web 应用程序,我在我的 context.xml 中使用 swallowOutput="true" 以实现不同的'per -webapp'-log-outp
我是一名优秀的程序员,十分优秀!