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;
18
19 import org.apache.logging.log4j.message.Message;
20 import org.apache.logging.log4j.util.Supplier;
21
22
23 /**
24 * Interface for constructing log events before logging them. Instances of LogBuilders should only be created
25 * by calling one of the Logger methods that return a LogBuilder.
26 */
27 public interface LogBuilder {
28
29 public static final LogBuilder NOOP = new LogBuilder() {};
30
31 /**
32 * Includes a Marker in the log event. Interface default method does nothing.
33 * @param marker The Marker to log.
34 * @return The LogBuilder.
35 */
36 default LogBuilder withMarker(Marker marker) {
37 return this;
38 }
39
40 /**
41 * Includes a Throwable in the log event. Interface default method does nothing.
42 * @param throwable The Throwable to log.
43 * @return the LogBuilder.
44 */
45 default LogBuilder withThrowable(Throwable throwable) {
46 return this;
47 }
48
49 /**
50 * An implementation will calculate the caller's stack frame and include it in the log event.
51 * Interface default method does nothing.
52 * @return The LogBuilder.
53 */
54 default LogBuilder withLocation() {
55 return this;
56 }
57
58 /**
59 * Adds the specified stack trace element to the log event. Interface default method does nothing.
60 * @param location The stack trace element to include in the log event.
61 * @return The LogBuilder.
62 */
63 default LogBuilder withLocation(StackTraceElement location) {
64 return this;
65 }
66
67 /**
68 * Causes all the data collected to be logged along with the message. Interface default method does nothing.
69 * @param message The message to log.
70 */
71 default void log(CharSequence message) {
72 }
73
74 /**
75 * Causes all the data collected to be logged along with the message. Interface default method does nothing.
76 * @param message The message to log.
77 */
78 default void log(String message) {
79 }
80
81 /**
82 * Logs a message with parameters. Interface default method does nothing.
83 *
84 * @param message the message to log; the format depends on the message factory.
85 * @param params parameters to the message.
86 *
87 * @see org.apache.logging.log4j.util.Unbox
88 */
89 default void log(String message, Object... params) {
90 }
91
92 /**
93 * Causes all the data collected to be logged along with the message and parameters.
94 * Interface default method does nothing.
95 * @param message The message.
96 * @param params Parameters to the message.
97 */
98 default void log(String message, Supplier<?>... params) {
99 }
100
101 /**
102 * Causes all the data collected to be logged along with the message. Interface default method does nothing.
103 * @param message The message to log.
104 */
105 default void log(Message message) {
106 }
107
108 /**
109 * Causes all the data collected to be logged along with the message. Interface default method does nothing.
110 * @param messageSupplier The supplier of the message to log.
111 */
112 default void log(Supplier<Message> messageSupplier) {
113 }
114
115 /**
116 * Causes all the data collected to be logged along with the message. Interface default method does nothing.
117 * @param message The message to log.
118 */
119 default void log(Object message) {
120 }
121
122 /**
123 * Logs a message with parameters. Interface default method does nothing.
124 *
125 * @param message the message to log; the format depends on the message factory.
126 * @param p0 parameter to the message.
127 *
128 * @see org.apache.logging.log4j.util.Unbox
129 */
130 default void log(String message, Object p0) {
131 }
132
133 /**
134 * Logs a message with parameters. Interface default method does nothing.
135 *
136 * @param message the message to log; the format depends on the message factory.
137 * @param p0 parameter to the message.
138 * @param p1 parameter to the message.
139 *
140 * @see org.apache.logging.log4j.util.Unbox
141 */
142 default void log(String message, Object p0, Object p1) {
143 }
144
145 /**
146 * Logs a message with parameters. Interface default method does nothing.
147 *
148 * @param message the message to log; the format depends on the message factory.
149 * @param p0 parameter to the message.
150 * @param p1 parameter to the message.
151 * @param p2 parameter to the message.
152 *
153 * @see org.apache.logging.log4j.util.Unbox
154 */
155 default void log(String message, Object p0, Object p1, Object p2) {
156 }
157
158 /**
159 * Logs a message with parameters. Interface default method does nothing.
160 *
161 * @param message the message to log; the format depends on the message factory.
162 * @param p0 parameter to the message.
163 * @param p1 parameter to the message.
164 * @param p2 parameter to the message.
165 * @param p3 parameter to the message.
166 *
167 * @see org.apache.logging.log4j.util.Unbox
168 */
169 default void log(String message, Object p0, Object p1, Object p2, Object p3) {
170 }
171
172 /**
173 * Logs a message with parameters. Interface default method does nothing.
174 *
175 * @param message the message to log; the format depends on the message factory.
176 * @param p0 parameter to the message.
177 * @param p1 parameter to the message.
178 * @param p2 parameter to the message.
179 * @param p3 parameter to the message.
180 * @param p4 parameter to the message.
181 *
182 * @see org.apache.logging.log4j.util.Unbox
183 */
184 default void log(String message, Object p0, Object p1, Object p2, Object p3, Object p4) {
185 }
186
187 /**
188 * Logs a message with parameters. Interface default method does nothing.
189 *
190 * @param message the message to log; the format depends on the message factory.
191 * @param p0 parameter to the message.
192 * @param p1 parameter to the message.
193 * @param p2 parameter to the message.
194 * @param p3 parameter to the message.
195 * @param p4 parameter to the message.
196 * @param p5 parameter to the message.
197 *
198 * @see org.apache.logging.log4j.util.Unbox
199 */
200 default void log(String message, Object p0, Object p1, Object p2, Object p3, Object p4, Object p5) {
201 }
202
203 /**
204 * Logs a message with parameters.
205 *
206 * @param message the message to log; the format depends on the message factory.
207 * @param p0 parameter to the message.
208 * @param p1 parameter to the message.
209 * @param p2 parameter to the message.
210 * @param p3 parameter to the message.
211 * @param p4 parameter to the message.
212 * @param p5 parameter to the message.
213 * @param p6 parameter to the message.
214 *
215 * @see org.apache.logging.log4j.util.Unbox
216 */
217 default void log(String message, Object p0, Object p1, Object p2, Object p3, Object p4, Object p5, Object p6) {
218 }
219
220 /**
221 * Logs a message with parameters. Interface default method does nothing.
222 *
223 * @param message the message to log; the format depends on the message factory.
224 * @param p0 parameter to the message.
225 * @param p1 parameter to the message.
226 * @param p2 parameter to the message.
227 * @param p3 parameter to the message.
228 * @param p4 parameter to the message.
229 * @param p5 parameter to the message.
230 * @param p6 parameter to the message.
231 * @param p7 parameter to the message.
232 *
233 * @see org.apache.logging.log4j.util.Unbox
234 */
235 default void log(String message, Object p0, Object p1, Object p2, Object p3, Object p4, Object p5, Object p6,
236 Object p7) {
237 }
238
239 /**
240 * Logs a message with parameters. Interface default method does nothing.
241 *
242 * @param message the message to log; the format depends on the message factory.
243 * @param p0 parameter to the message.
244 * @param p1 parameter to the message.
245 * @param p2 parameter to the message.
246 * @param p3 parameter to the message.
247 * @param p4 parameter to the message.
248 * @param p5 parameter to the message.
249 * @param p6 parameter to the message.
250 * @param p7 parameter to the message.
251 * @param p8 parameter to the message.
252 *
253 * @see org.apache.logging.log4j.util.Unbox
254 */
255 default void log(String message, Object p0, Object p1, Object p2, Object p3, Object p4, Object p5, Object p6,
256 Object p7, Object p8) {
257 }
258
259 /**
260 * Logs a message with parameters. Interface default method does nothing.
261 *
262 * @param message the message to log; the format depends on the message factory.
263 * @param p0 parameter to the message.
264 * @param p1 parameter to the message.
265 * @param p2 parameter to the message.
266 * @param p3 parameter to the message.
267 * @param p4 parameter to the message.
268 * @param p5 parameter to the message.
269 * @param p6 parameter to the message.
270 * @param p7 parameter to the message.
271 * @param p8 parameter to the message.
272 * @param p9 parameter to the message.
273 *
274 * @see org.apache.logging.log4j.util.Unbox
275 */
276 default void log(String message, Object p0, Object p1, Object p2, Object p3, Object p4, Object p5, Object p6,
277 Object p7, Object p8, Object p9) {
278 }
279
280 /**
281 * Causes all the data collected to be logged. Default implementatoin does nothing.
282 */
283 default void log() {
284 }
285 }
286