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.core;
018
019import java.util.Collections;
020import java.util.Map;
021
022import org.apache.logging.log4j.Level;
023import org.apache.logging.log4j.Marker;
024import org.apache.logging.log4j.ThreadContext;
025import org.apache.logging.log4j.ThreadContext.ContextStack;
026import org.apache.logging.log4j.core.impl.ThrowableProxy;
027import org.apache.logging.log4j.core.time.Instant;
028import org.apache.logging.log4j.core.time.MutableInstant;
029import org.apache.logging.log4j.message.Message;
030import org.apache.logging.log4j.util.ReadOnlyStringMap;
031
032
033/**
034 * An abstract log event implementation with default values for all methods. The setters are no-ops.
035 */
036public abstract class AbstractLogEvent implements LogEvent {
037
038    private static final long serialVersionUID = 1L;
039
040    private volatile MutableInstant instant;
041
042    /**
043     * Subclasses should implement this method to provide an immutable version.
044     */
045    @Override
046    public LogEvent toImmutable() {
047        return this;
048    }
049
050    @Override
051    public ReadOnlyStringMap getContextData() {
052        return null;
053    }
054
055    /**
056     * Returns {@link Collections#emptyMap()}.
057     */
058    @Override
059    public Map<String, String> getContextMap() {
060        return Collections.emptyMap();
061    }
062
063    @Override
064    public ContextStack getContextStack() {
065        return ThreadContext.EMPTY_STACK;
066    }
067
068    @Override
069    public Level getLevel() {
070        return null;
071    }
072
073    @Override
074    public String getLoggerFqcn() {
075        return null;
076    }
077
078    @Override
079    public String getLoggerName() {
080        return null;
081    }
082
083    @Override
084    public Marker getMarker() {
085        return null;
086    }
087
088    @Override
089    public Message getMessage() {
090        return null;
091    }
092
093    @Override
094    public StackTraceElement getSource() {
095        return null;
096    }
097
098    @Override
099    public long getThreadId() {
100        return 0;
101    }
102
103    @Override
104    public String getThreadName() {
105        return null;
106    }
107
108    @Override
109    public int getThreadPriority() {
110        return 0;
111    }
112
113    @Override
114    public Throwable getThrown() {
115        return null;
116    }
117
118    @Override
119    public ThrowableProxy getThrownProxy() {
120        return null;
121    }
122
123    @Override
124    public long getTimeMillis() {
125        return 0;
126    }
127
128    @Override
129    public Instant getInstant() {
130        return getMutableInstant();
131    }
132
133    protected final MutableInstant getMutableInstant() {
134        if (instant == null) {
135            instant = new MutableInstant();
136        }
137        return instant;
138    }
139
140    @Override
141    public boolean isEndOfBatch() {
142        return false;
143    }
144
145    @Override
146    public boolean isIncludeLocation() {
147        return false;
148    }
149
150    @Override
151    public void setEndOfBatch(final boolean endOfBatch) {
152        // do nothing
153    }
154
155    @Override
156    public void setIncludeLocation(final boolean locationRequired) {
157        // do nothing
158    }
159
160    @Override
161    public long getNanoTime() {
162        return 0;
163    }
164}