View Javadoc

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  
18  package org.apache.logging.log4j.core;
19  
20  import org.apache.logging.log4j.Level;
21  import org.apache.logging.log4j.Marker;
22  import org.apache.logging.log4j.ThreadContext;
23  import org.apache.logging.log4j.message.Message;
24  
25  import java.io.Serializable;
26  import java.util.Map;
27  
28  /**
29   *
30   */
31  public interface LogEvent extends Serializable {
32  
33       /**
34       * Get level.
35       * @return level.
36       */
37      Level getLevel();
38  
39      /**
40       * Get logger name.
41       * @return logger name, may be null.
42       */
43      String getLoggerName();
44  
45      /**
46       * Get source of logging request.
47       * @return source of logging request, may be null.
48       */
49      StackTraceElement getSource();
50  
51      /**
52       * Get the message associated with the event.
53       *
54       * @return message.
55       */
56      Message getMessage();
57  
58      /**
59       * Get the Marker associated with the event.
60       * @return Marker
61       */
62      Marker getMarker();
63  
64      /**
65       * Get thread name.
66       * @return thread name, may be null.
67       * @doubt guess this could go into a thread context object too.
68       * (RG) Why?
69       */
70      String getThreadName();
71  
72  
73      /**
74       * Get event time in milliseconds since 1970.
75       * @return milliseconds since 1970.
76       */
77      long getMillis();
78  
79  
80      /**
81       * Get throwable associated with logging request.
82       * @return throwable, may be null.
83       */
84      Throwable getThrown();
85  
86  
87      /**
88       * Get the MDC data.
89       *
90       * @return A copy of the Mapped Diagnostic Context or null.
91       */
92      Map<String, String> getContextMap();
93  
94      /**
95       * Get the NDC data.
96       *
97       * @return A copy of the Nested Diagnostic Context or null;
98       */
99      ThreadContext.ContextStack getContextStack();
100 
101     /**
102      * Returns the fully qualified class name of the caller of the logging api.
103      * @return The fully qualified class name of the caller.
104      */
105     String getFQCN();
106 
107     /**
108      * Returns whether the source of the logging request is required downstream.
109      * Asynchronous Loggers and Appenders use this flag to determine whether
110      * to take a {@code StackTrace} snapshot or not before handing off this
111      * event to another thread.
112      * @return {@code true} if the source of the logging request is required 
113      *          downstream, {@code false} otherwise.
114      * @see #getSource()
115      */
116     // see also LOG4J2-153
117     boolean isIncludeLocation();
118 
119     /**
120      * Sets whether the source of the logging request is required downstream.
121      * Asynchronous Loggers and Appenders use this flag to determine whether
122      * to take a {@code StackTrace} snapshot or not before handing off this
123      * event to another thread.
124      * @param locationRequired {@code true} if the source of the logging request 
125      *           is required downstream, {@code false} otherwise.
126      * @see #getSource()
127      */
128     void setIncludeLocation(boolean locationRequired);
129     
130     /**
131      * Returns {@code true} if this event is the last one in a batch, 
132      * {@code false} otherwise. Used by asynchronous Loggers and Appenders to
133      * signal to buffered downstream components when to flush to disk, as a
134      * more efficient alternative to the {@code immediateFlush=true} 
135      * configuration.
136      * @return whether this event is the last one in a batch.
137      */
138     // see also LOG4J2-164
139     boolean isEndOfBatch();
140     
141     /**
142      * Sets whether this event is the last one in a batch.
143      * Used by asynchronous Loggers and Appenders to signal to buffered 
144      * downstream components when to flush to disk, as a more efficient 
145      * alternative to the {@code immediateFlush=true} configuration.
146      * @param endOfBatch {@code true} if this event is the last one in a batch, 
147      * {@code false} otherwise.
148      */
149     void setEndOfBatch(boolean endOfBatch);
150 }