我想答案可能会有所不同,具体取决于所使用的处理程序,但假设使用了 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/