Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does log4j2 file appenders use for file encoding/format?

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.

like image 682
Adam Marcionek Avatar asked Apr 15 '16 19:04

Adam Marcionek


3 Answers

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.

like image 65
rgoers Avatar answered Oct 17 '22 19:10

rgoers


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.

like image 36
user2015398 Avatar answered Oct 17 '22 18:10

user2015398


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.

like image 10
Remko Popma Avatar answered Oct 17 '22 17:10

Remko Popma