[英]Encode pattern layout in apache log4j
Trying to use the following pattern layout to print encoded log messages, so that \\n will not be printed as a new line in the logs. 尝试使用以下模式布局来打印编码的日志消息,以便\\ n不会在日志中作为新行打印。
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{MM-dd-yyyy HH:mm:ss,SSS} %5p [%t] (%F:%L) - %enc{%m}%n"/>
</layout>
But it literally prints %enc{
before every message and prints }
at the end of the messages, instead of encoding them. 但是它实际上是在每条消息之前打印%enc{
,并在消息末尾打印}
,而不是对它们进行编码。 \\n is also not being replaced. \\ n也不会被替换。
Example: For this code logger.info("my \\n message")
following is the output log 示例:对于此代码logger.info("my \\n message")
以下是输出日志
08-01-2018 01:26:37,642 INFO [localhost-startStop-1] (ClassName1.java:53) - %enc{my
message}
instead it should be like, 相反,它应该像
08-01-2018 01:26:37,642 INFO [localhost-startStop-1] (ClassName1.java:53) - my message
Followed this document https://logging.apache.org/log4j/log4j-2.1/manual/layouts.html But I'm not sure what is wrong with the pattern. 遵循本文档https://logging.apache.org/log4j/log4j-2.1/manual/layouts.html但我不确定该模式有什么问题。
You should determine the encoding format in curly brackets. 您应该在大括号中确定编码格式。 For example %enc{%m}{HTML}
encodes the message in HTML format. 例如, %enc{%m}{HTML}
将消息编码为HTML格式。 You could also use CRLF: enc{%m}{CRLF}
您也可以使用CRLF: enc{%m}{CRLF}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.