001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements. See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache license, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License. You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the license for the specific language governing permissions and
015     * limitations under the license.
016     */
017    package org.apache.logging.log4j.message;
018    
019    import java.io.Serializable;
020    
021    /**
022     * An interface for various Message implementations that can be logged. Messages can act as wrappers
023     * around Objects so that user can have control over converting Objects to Strings when necessary without
024     * requiring complicated formatters and as a way to manipulate the message based on information available
025     * at runtime such as the locale of the system.
026     *<p>
027     * Note: Message objects should not be considered to be thread safe nor should they be assumed to be
028     * safely reusable even on the same thread. The logging system may provide information to the Message
029     * objects and the Messages might be queued for asynchronous delivery. Thus, any modifications to a
030     * Message object by an application should by avoided after the Message has been passed as a parameter on
031     * a Logger method.
032     * </p>
033     * @doubt Interfaces should rarely extend Serializable according to Effective Java 2nd Ed pg 291.
034     * (RG) That section also says "If a class or interface exists primarily to participate in a framework that
035     * requires all participants to implement Serializable, then it makes perfect sense for the class or
036     * interface to implement or extend Serializable". Such is the case here as the LogEvent must be Serializable.
037     */
038    public interface Message extends Serializable {
039        /**
040         * Returns the Message formatted as a String. Each Message implementation determines the
041         * appropriate way to format the data encapsulated in the Message. Messages that provide
042         * more than one way of formatting the Message will implement MultiformatMessage.
043         *
044         * @return The message String.
045         */
046        String getFormattedMessage();
047    
048        /**
049         * Returns the format portion of the Message.
050         *
051         * @return The message format. Some implementations, such as ParameterizedMessage, will use this as
052         * the message "pattern". Other Messages may simply return an empty String.
053         * @doubt Do all messages have a format?  What syntax?  Using a Formatter object could be cleaner.
054         * (RG) In SimpleMessage the format is identical to the formatted message. In ParameterizedMessage and
055         * StructuredDataMessage it is not. It is up to the Message implementer to determine what this
056         * method will return. A Formatter is inappropriate as this is very specific to the Message
057         * implementation so it isn't clear to me how having a Formatter separate from the Message would be cleaner.
058         */
059        String getFormat();
060    
061        /**
062         * Returns parameter values, if any.
063         *
064         * @return An array of parameter values or null.
065         */
066        Object[] getParameters();
067    }