What file format does log4j2 use when it writes to rollingfileappender? Furthermore, is there a way to change it? What I'd like to do use use UTF-16.
What does log4j2 file appenders use for file encoding/format?
The Charset is specified on the Layout. AbstractStringLayout
defaults to UTF-8.
You should be able to change that by specifying charset="UTF-16"
on the Layout configuration.
Thank you! It did not occur to me it was part of the pattern as I was looking all over the appenders for it. Information on layouts are here –
Seeing
+10. It may be worth pointing out that most layouts including PatternLayout extend AbstractStringLayout so they all accept a charset parameter. –
Rik
You are right! It works in my log4j2.xml
<PatternLayout pattern="<mypattern>" charset="UTF-8" />
–
Jetport Small correction on Ralph's answer: for PatternLayout the default charset is the system default. This is important because for example the Windows console won't be able to correctly display UTF-8 on Japanese Windows.
If you use log4j.properties, configure it as follow:
appender.rolling.layout.charset = UTF-16
or make the corresponding configurations in your xml configuration file.
You should provide a larger excerpt of your configuration, because the current content of your answer can give the wrong impression that
appender.rolling.layout.charset
is a universally valid configuration property. In reality rolling
and layout
are arbitrary identifiers. –
Repugnance © 2022 - 2024 — McMap. All rights reserved.