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 */ 017package org.apache.logging.log4j.message; 018 019/** 020 * Creates {@link FormattedMessage} instances for {@link MessageFactory2} methods (and {@link MessageFactory} by 021 * extension.) 022 * <p> 023 * Enables the use of {@link java.util.Formatter} strings in message strings. 024 * </p> 025 * <p> 026 * Creates {@link StringFormattedMessage} instances for {@link #newMessage(String, Object...)}. 027 * </p> 028 * <p> 029 * This class is immutable. 030 * </p> 031 * <h4>Note to implementors</h4> 032 * <p> 033 * This class implements all {@link MessageFactory2} methods. 034 * </p> 035 */ 036public final class StringFormatterMessageFactory extends AbstractMessageFactory { 037 038 /** 039 * Instance of StringFormatterMessageFactory. 040 */ 041 public static final StringFormatterMessageFactory INSTANCE = new StringFormatterMessageFactory(); 042 private static final long serialVersionUID = -1626332412176965642L; 043 044 /** 045 * Constructs a message factory with default flow strings. 046 */ 047 public StringFormatterMessageFactory() { 048 } 049 050 /** 051 * Creates {@link StringFormattedMessage} instances. 052 * 053 * @param message The message pattern. 054 * @param params The parameters to the message. 055 * @return The Message. 056 * 057 * @see MessageFactory#newMessage(String, Object...) 058 */ 059 @Override 060 public Message newMessage(final String message, final Object... params) { 061 return new StringFormattedMessage(message, params); 062 } 063 064 /** 065 * @since 2.6.1 066 */ 067 @Override 068 public Message newMessage(final String message, final Object p0) { 069 return new StringFormattedMessage(message, p0); 070 } 071 072 /** 073 * @since 2.6.1 074 */ 075 @Override 076 public Message newMessage(final String message, final Object p0, final Object p1) { 077 return new StringFormattedMessage(message, p0, p1); 078 } 079 080 /** 081 * @since 2.6.1 082 */ 083 @Override 084 public Message newMessage(final String message, final Object p0, final Object p1, final Object p2) { 085 return new StringFormattedMessage(message, p0, p1, p2); 086 } 087 088 /** 089 * @since 2.6.1 090 */ 091 @Override 092 public Message newMessage(final String message, final Object p0, final Object p1, final Object p2, final Object p3) { 093 return new StringFormattedMessage(message, p0, p1, p2, p3); 094 } 095 096 /** 097 * @since 2.6.1 098 */ 099 @Override 100 public Message newMessage(final String message, final Object p0, final Object p1, final Object p2, final Object p3, final Object p4) { 101 return new StringFormattedMessage(message, p0, p1, p2, p3, p4); 102 } 103 104 /** 105 * @since 2.6.1 106 */ 107 @Override 108 public Message newMessage(final String message, final Object p0, final Object p1, final Object p2, final Object p3, final Object p4, final Object p5) { 109 return new StringFormattedMessage(message, p0, p1, p2, p3, p4, p5); 110 } 111 112 /** 113 * @since 2.6.1 114 */ 115 @Override 116 public Message newMessage(final String message, final Object p0, final Object p1, final Object p2, final Object p3, final Object p4, final Object p5, 117 final Object p6) { 118 return new StringFormattedMessage(message, p0, p1, p2, p3, p4, p5, p6); 119 } 120 121 /** 122 * @since 2.6.1 123 */ 124 @Override 125 public Message newMessage(final String message, final Object p0, final Object p1, final Object p2, final Object p3, final Object p4, final Object p5, 126 final Object p6, final Object p7) { 127 return new StringFormattedMessage(message, p0, p1, p2, p3, p4, p5, p6, p7); 128 } 129 130 /** 131 * @since 2.6.1 132 */ 133 @Override 134 public Message newMessage(final String message, final Object p0, final Object p1, final Object p2, final Object p3, final Object p4, final Object p5, 135 final Object p6, final Object p7, final Object p8) { 136 return new StringFormattedMessage(message, p0, p1, p2, p3, p4, p5, p6, p7, p8); 137 } 138 139 /** 140 * @since 2.6.1 141 */ 142 @Override 143 public Message newMessage(final String message, final Object p0, final Object p1, final Object p2, final Object p3, final Object p4, final Object p5, 144 final Object p6, final Object p7, final Object p8, final Object p9) { 145 return new StringFormattedMessage(message, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9); 146 } 147}