1

前言

本篇主要关于常被Appender(记录器)使用的,用来格式化消息的Layout(布局器)组件。

正文

引入Layout:被Appender使用,作用是格式化消息。

chapter 2

More often than not, users wish to customize not only the output destination but also the output format. This is accomplished by associating a layout with an appender. The layout is responsible for formatting the logging request according to the user's wishes, whereas an appender takes care of sending the formatted output to its destination. The PatternLayout, part of the standard logback distribution, lets the user specify the output format according to conversion patterns similar to the C language printf function.

这段话最重要的内容就是“用户如何定制输出的格式呢?这通过关联一个布置器(layout)到一个输出器上来实现”。这句话表明布置器是与输出器关联而不是与日志记录器关联。

之后举了一个例子讲了一下布置器(layout)的输出格式(pattern)的写法。

For example, the PatternLayout with the conversion pattern "%-4relative [%thread] %-5level %logger{32} - %msg%n" will output something akin to:

176 [main] DEBUG manual.architecture.HelloWorld2 - Hello world.

The first field is the number of milliseconds elapsed since the start of the program. The second field is the thread making the log request. The third field is the level of the log request. The fourth field is the name of the logger associated with the log request. The text after the '-' is the message of the request.


阳光号
129 声望5 粉丝

引用和评论

0 条评论