You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "Marcono1234 (Jira)" <ji...@apache.org> on 2020/09/20 17:48:00 UTC
[jira] [Created] (LOG4J2-2929) PatternLayout / RFC5424 Layout
should use UTF-8 as default charset unless used for Console
Marcono1234 created LOG4J2-2929:
-----------------------------------
Summary: PatternLayout / RFC5424 Layout should use UTF-8 as default charset unless used for Console
Key: LOG4J2-2929
URL: https://issues.apache.org/jira/browse/LOG4J2-2929
Project: Log4j 2
Issue Type: Wish
Reporter: Marcono1234
Currently {{PatternLayout}} always uses the default charset if none is specified explicitly. This can be annoying because probably nearly all appenders except {{Console}} support UTF-8.
For these appenders, characters which the default charset does not support would be displayed as {{?}} even though the appender would support them, causing information loss.
For appenders which send the log data to a remote server this could even cause incorrect behavior because that remote server might have a different default charset.
Would it therefore be possibly to use UTF-8 as default unless the enclosing appender is the {{Console}} appender? This could possibly even be implemented in a clean way:
- Add default method {{Appender.usesDefaultCharset()}} which returns {{false}}; override it for {{Console}} appender to return {{true}}
- When creating {{PatternLayout}}:
-- If charset is explicitly specified: Use that; *don't* consult {{Appender.usesDefaultCharset()}}
-- If no charset is specified consult {{usesDefaultCharset()}}
Note though that the {{Console}} appender actually uses the console charset which might differ from the default charset, see LOG4J2-1636.
So maybe having a method {{Appender.getDefaultCharset()}} would be better?
----
The same probably also applies to the RFC5424 layout.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)