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.core.impl;
18
19 import org.apache.logging.log4j.message.Message;
20 import org.apache.logging.log4j.util.StringBuilderFormattable;
21
22 import java.util.Arrays;
23
24 /**
25 * <em>Consider this class private.</em>
26 *
27 * {@link MementoMessage} is intended to be used when we need to make an
28 * immutable copy of a {@link Message} without forgetting the original
29 * {@link Message#getFormat()} and {@link Message#getParameters()} values.
30 *
31 * @since 3.0
32 */
33 public final class MementoMessage implements Message, StringBuilderFormattable {
34
35 private final String formattedMessage;
36 private final String format;
37 private final Object[] parameters;
38
39 public MementoMessage(final String formattedMessage, final String format, final Object[] parameters) {
40 this.formattedMessage = formattedMessage;
41 this.format = format;
42 this.parameters = parameters;
43 }
44
45 @Override
46 public String getFormattedMessage() {
47 return formattedMessage;
48 }
49
50 @Override
51 public String getFormat() {
52 return format;
53 }
54
55 @Override
56 public Object[] getParameters() {
57 return parameters;
58 }
59
60 /**
61 * Always returns null.
62 *
63 * @return null
64 */
65 @Override
66 public Throwable getThrowable() {
67 return null;
68 }
69
70 @Override
71 public void formatTo(final StringBuilder buffer) {
72 buffer.append(formattedMessage);
73 }
74
75 @Override
76 public String toString() {
77 return "MementoMessage{" +
78 "formattedMessage='" + formattedMessage + '\'' +
79 ", format='" + format + '\'' +
80 ", parameters=" + Arrays.toString(parameters) +
81 '}';
82 }
83 }