[
https://issues.apache.org/jira/browse/LOG4J2-2929?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17199089#comment-17199089
]
Remko Popma commented on LOG4J2-2929:
-------------------------------------
I like the idea of the layout asking the appender for its preferred charset.
Should we add a method {{Appender.getPreferredCharset()}}?
> 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
> Priority: Major
>
> 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)