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     */
017    
018    package org.apache.logging.log4j.core;
019    
020    import org.apache.logging.log4j.Level;
021    import org.apache.logging.log4j.Marker;
022    import org.apache.logging.log4j.ThreadContext;
023    import org.apache.logging.log4j.message.Message;
024    
025    import java.io.Serializable;
026    import java.util.Map;
027    
028    /**
029     *
030     */
031    public interface LogEvent extends Serializable {
032    
033         /**
034         * Get level.
035         * @return level.
036         */
037        Level getLevel();
038    
039        /**
040         * Get logger name.
041         * @return logger name, may be null.
042         */
043        String getLoggerName();
044    
045        /**
046         * Get source of logging request.
047         * @return source of logging request, may be null.
048         */
049        StackTraceElement getSource();
050    
051        /**
052         * Get the message associated with the event.
053         *
054         * @return message.
055         */
056        Message getMessage();
057    
058        /**
059         * Get the Marker associated with the event.
060         * @return Marker
061         */
062        Marker getMarker();
063    
064        /**
065         * Get thread name.
066         * @return thread name, may be null.
067         * @doubt guess this could go into a thread context object too.
068         * (RG) Why?
069         */
070        String getThreadName();
071    
072    
073        /**
074         * Get event time in milliseconds since 1970.
075         * @return milliseconds since 1970.
076         */
077        long getMillis();
078    
079    
080        /**
081         * Get throwable associated with logging request.
082         * @return throwable, may be null.
083         */
084        Throwable getThrown();
085    
086    
087        /**
088         * Get the MDC data.
089         *
090         * @return A copy of the Mapped Diagnostic Context or null.
091         */
092        Map<String, String> getContextMap();
093    
094        /**
095         * Get the NDC data.
096         *
097         * @return A copy of the Nested Diagnostic Context or null;
098         */
099        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    }