1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache license, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the license for the specific language governing permissions and 15 * limitations under the license. 16 */ 17 package org.apache.logging.log4j.message; 18 19 import java.io.Serializable; 20 21 /** 22 * An interface for various Message implementations that can be logged. Messages can act as wrappers 23 * around Objects so that user can have control over converting Objects to Strings when necessary without 24 * requiring complicated formatters and as a way to manipulate the message based on information available 25 * at runtime such as the locale of the system. 26 *<p> 27 * Note: Message objects should not be considered to be thread safe nor should they be assumed to be 28 * safely reusable even on the same thread. The logging system may provide information to the Message 29 * objects and the Messages might be queued for asynchronous delivery. Thus, any modifications to a 30 * Message object by an application should by avoided after the Message has been passed as a parameter on 31 * a Logger method. 32 * </p> 33 * @doubt Interfaces should rarely extend Serializable according to Effective Java 2nd Ed pg 291. 34 * (RG) That section also says "If a class or interface exists primarily to participate in a framework that 35 * requires all participants to implement Serializable, then it makes perfect sense for the class or 36 * interface to implement or extend Serializable". Such is the case here as the LogEvent must be Serializable. 37 */ 38 public interface Message extends Serializable { 39 /** 40 * Returns the Message formatted as a String. Each Message implementation determines the 41 * appropriate way to format the data encapsulated in the Message. Messages that provide 42 * more than one way of formatting the Message will implement MultiformatMessage. 43 * 44 * @return The message String. 45 */ 46 String getFormattedMessage(); 47 48 /** 49 * Returns the format portion of the Message. 50 * 51 * @return The message format. Some implementations, such as ParameterizedMessage, will use this as 52 * the message "pattern". Other Messages may simply return an empty String. 53 * @doubt Do all messages have a format? What syntax? Using a Formatter object could be cleaner. 54 * (RG) In SimpleMessage the format is identical to the formatted message. In ParameterizedMessage and 55 * StructuredDataMessage it is not. It is up to the Message implementer to determine what this 56 * method will return. A Formatter is inappropriate as this is very specific to the Message 57 * implementation so it isn't clear to me how having a Formatter separate from the Message would be cleaner. 58 */ 59 String getFormat(); 60 61 /** 62 * Returns parameter values, if any. 63 * 64 * @return An array of parameter values or null. 65 */ 66 Object[] getParameters(); 67 }