[
https://issues.apache.org/jira/browse/LOG4J2-1326?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15212657#comment-15212657
]
Remko Popma commented on LOG4J2-1326:
-------------------------------------
Gary, if you log a domain object that implements StringBuilderFormattable,
log4j will call its formatTo(StringBuilder) on it. However, this is a Log4j
interface and users may dislike the resulting dependency on log4j. CharSequence
is a JDK interface so is less invasive. Log4j can log it by looping over its
characters one by one.
The goal is to avoid calling toString(), because that creates garbage (at least
for mutable objects that cannot cache their string representation).
In messaging applications that aim for low to zero-GC, data is often stored in
ByteBuffers instead of fields, and a domain object is just a mutable wrapper
with an interface that lets client code use that binary blob as if it is a
normal object. In this kind of design, text fields can be represented as
CharSequence. You would not want to call toString on them though, but you want
them to be consumed char by char.
> API change: add methods for logging CharSequences (was: Provide support for
> CharSequence parameters for low and zero-GC applications)
> -------------------------------------------------------------------------------------------------------------------------------------
>
> Key: LOG4J2-1326
> URL: https://issues.apache.org/jira/browse/LOG4J2-1326
> Project: Log4j 2
> Issue Type: New Feature
> Components: API
> Affects Versions: 2.5
> Reporter: Vlad Shurupov
> Labels: features, performance
>
> Currently, the preferred way of logging character sequences in log4j 2 is by
> passing in tokens of type {{java.lang.String}}. It would be very beneficial
> if the API could provide methods that take {{java.lang.CharSequence}} tokens.
> This would allow high performance zero or low-GC applications to re-use the
> existing mutable structures implementing {{java.lang.CharSequence}} for
> continuous logging without new objects being created.
> A high-performance implementation of the logger would be expected to copy out
> the contents of a single or multiple instances of {{java.lang.CharSequence}}
> so that they could be re-used in the subsequent logging call.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]