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;
018
019import org.apache.logging.log4j.message.Message;
020import org.apache.logging.log4j.util.Supplier;
021
022
023/**
024 * Interface for constructing log events before logging them. Instances of LogBuilders should only be created
025 * by calling one of the Logger methods that return a LogBuilder.
026 */
027public interface LogBuilder {
028
029    public static final LogBuilder NOOP = new LogBuilder() {};
030
031    /**
032     * Includes a Marker in the log event. Interface default method does nothing.
033     * @param marker The Marker to log.
034     * @return The LogBuilder.
035     */
036    default LogBuilder withMarker(Marker marker) {
037        return this;
038    }
039
040    /**
041     * Includes a Throwable in the log event. Interface default method does nothing.
042     * @param throwable The Throwable to log.
043     * @return the LogBuilder.
044     */
045    default LogBuilder withThrowable(Throwable throwable) {
046        return this;
047    }
048
049    /**
050     * An implementation will calculate the caller's stack frame and include it in the log event.
051     * Interface default method does nothing.
052     * @return The LogBuilder.
053     */
054    default LogBuilder withLocation() {
055        return this;
056    }
057
058    /**
059     * Adds the specified stack trace element to the log event. Interface default method does nothing.
060     * @param location The stack trace element to include in the log event.
061     * @return The LogBuilder.
062     */
063    default LogBuilder withLocation(StackTraceElement location) {
064        return this;
065    }
066
067    /**
068     * Causes all the data collected to be logged along with the message. Interface default method does nothing.
069     * @param message The message to log.
070     */
071    default void log(CharSequence message) {
072    }
073
074    /**
075     * Causes all the data collected to be logged along with the message. Interface default method does nothing.
076     * @param message The message to log.
077     */
078    default void log(String message) {
079    }
080
081    /**
082     * Logs a message with parameters. Interface default method does nothing.
083     *
084     * @param message the message to log; the format depends on the message factory.
085     * @param params parameters to the message.
086     *
087     * @see org.apache.logging.log4j.util.Unbox
088     */
089    default void log(String message, Object... params) {
090    }
091
092    /**
093     * Causes all the data collected to be logged along with the message and parameters.
094     * Interface default method does nothing.
095     * @param message The message.
096     * @param params Parameters to the message.
097     */
098    default void log(String message, Supplier<?>... params) {
099    }
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}