Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 12932200BCF for ; Sun, 20 Nov 2016 16:56:02 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 0F174160AFE; Sun, 20 Nov 2016 15:56:02 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 38043160B07 for ; Sun, 20 Nov 2016 16:56:01 +0100 (CET) Received: (qmail 58307 invoked by uid 500); 20 Nov 2016 15:56:00 -0000 Mailing-List: contact log4j-dev-help@logging.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Log4J Developers List" Reply-To: "Log4J Developers List" Delivered-To: mailing list log4j-dev@logging.apache.org Received: (qmail 58170 invoked by uid 99); 20 Nov 2016 15:56:00 -0000 Received: from arcas.apache.org (HELO arcas) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 20 Nov 2016 15:56:00 +0000 Received: from arcas.apache.org (localhost [127.0.0.1]) by arcas (Postfix) with ESMTP id 2F2F42C2B10 for ; Sun, 20 Nov 2016 15:56:00 +0000 (UTC) Date: Sun, 20 Nov 2016 15:56:00 +0000 (UTC) From: "Remko Popma (JIRA)" To: log4j-dev@logging.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Updated] (LOG4J2-1718) Introduce marker interface AsynchronouslyFormattable MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Sun, 20 Nov 2016 15:56:02 -0000 [ https://issues.apache.org/jira/browse/LOG4J2-1718?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Remko Popma updated LOG4J2-1718: -------------------------------- Description: Logging mutable objects asynchronously always has the risk that the object is modified between the time the logger is called and the time the log message is formatted and written to disk. Log4j built-in Message implementation classes prevent this race condition in one of two ways: * Implement the {{ReusableMessage}} interface. Asynchronous logging components in log4j cooperate with ReusableMessages by copying their _content_ (formatted message, parameters) into the LogEvent rather than passing the Message instance itself. This ensures the formatted message will not change when the mutable object is modified. * Cache the formatted message when the {{getFormattedMessage}} method is called. Asynchronous logging components in log4j will call this method before passing the Message object to another thread. (See LOG4J2-763.) For example, FormattedMessage, LocalizedMessage, MessageFormatMessage, ObjectArrayMessage, ObjectMessage, ParameterizedMessage, SimpleMessage and StringFormattedMessage take this approach. Once initialized, {{getFormattedMessage}} returns the cached String, so changes to the mutable object will not impact the formatted message. For performance reasons, users can choose to format _all_ messages in the background by setting system property {{log4j.format.msg.async}} to true. (See LOG4J2-898.) Some messages do not capture mutable objects and are not at risk of the above race condition. This ticket proposes to introduce interface {{AsynchronouslyFormattable}} as a marker interface to signal to asynchronous logging components that messages of this type can safely be passed to a background thread without calling {{getFormattedMessage}} first. This benefits performance and avoids creating unnecessary (unused) objects. Candidates for implementing this interface are message implementations which do not cache anything in {{getFormattedMessage}}: * flow messages (SimpleEntryMessage and SimpleExitMessage) * MapMessage * StructuredDataMessage * ThreadDumpMessage (threads are cached in the constructor) was: Logging mutable objects asynchronously always has the risk that the object is modified between the time the logger is called and the time the log message is formatted and written to disk. Log4j built-in Message implementation classes prevent this race condition in one of two ways: * Implement the {{ReusableMessage}} interface. Asynchronous logging components in log4j cooperate with ReusableMessages by copying their _content_ (formatted message, parameters) into the LogEvent rather than passing the Message instance itself. This ensures the formatted message will not change when the mutable object is modified. * Cache the formatted message when the {{getFormattedMessage}} method is called. Asynchronous logging components in log4j will call this method before passing the Message object to another thread. (See LOG4J2-763.) For example, FormattedMessage, LocalizedMessage, MessageFormatMessage, ObjectArrayMessage, ObjectMessage, ParameterizedMessage, SimpleMessage and StringFormattedMessage take this approach. Once initialized, {{getFormattedMessage}} returns the cached String, so changes to the mutable object will not impact the formatted message. For performance reasons, users can choose to format _all_ messages in the background by setting system property {{log4j.format.msg.async}} to true. (See LOG4J2-898.) Some messages do not capture mutable objects and are not at risk of the above race condition. This ticket proposes to introduce interface {{AsynchronouslyFormattable}} as a marker interface to signal to asynchronous logging components that messages of this type can safely be passed to a background thread without calling {{getFormattedMessage}} first. This benefits performance and avoids creating unnecessary (unused) objects. Candidates for implementing this interface are message implementations which do not cache anything in {{getFormattedMessage}}: * flow messages (SimpleEntryMessage and SimpleExitMessage) * MapMessage * StructuredDataMessage > Introduce marker interface AsynchronouslyFormattable > ---------------------------------------------------- > > Key: LOG4J2-1718 > URL: https://issues.apache.org/jira/browse/LOG4J2-1718 > Project: Log4j 2 > Issue Type: Improvement > Components: API > Affects Versions: 2.7 > Reporter: Remko Popma > Assignee: Remko Popma > Fix For: 2.8 > > > Logging mutable objects asynchronously always has the risk that the object is modified between the time the logger is called and the time the log message is formatted and written to disk. > Log4j built-in Message implementation classes prevent this race condition in one of two ways: > * Implement the {{ReusableMessage}} interface. Asynchronous logging components in log4j cooperate with ReusableMessages by copying their _content_ (formatted message, parameters) into the LogEvent rather than passing the Message instance itself. This ensures the formatted message will not change when the mutable object is modified. > * Cache the formatted message when the {{getFormattedMessage}} method is called. Asynchronous logging components in log4j will call this method before passing the Message object to another thread. (See LOG4J2-763.) For example, FormattedMessage, LocalizedMessage, MessageFormatMessage, ObjectArrayMessage, ObjectMessage, ParameterizedMessage, SimpleMessage and StringFormattedMessage take this approach. Once initialized, {{getFormattedMessage}} returns the cached String, so changes to the mutable object will not impact the formatted message. > For performance reasons, users can choose to format _all_ messages in the background by setting system property {{log4j.format.msg.async}} to true. (See LOG4J2-898.) > Some messages do not capture mutable objects and are not at risk of the above race condition. > This ticket proposes to introduce interface {{AsynchronouslyFormattable}} as a marker interface to signal to asynchronous logging components that messages of this type can safely be passed to a background thread without calling {{getFormattedMessage}} first. > This benefits performance and avoids creating unnecessary (unused) objects. > Candidates for implementing this interface are message implementations which do not cache anything in {{getFormattedMessage}}: > * flow messages (SimpleEntryMessage and SimpleExitMessage) > * MapMessage > * StructuredDataMessage > * ThreadDumpMessage (threads are cached in the constructor) -- This message was sent by Atlassian JIRA (v6.3.4#6332) --------------------------------------------------------------------- To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org For additional commands, e-mail: log4j-dev-help@logging.apache.org