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  package org.apache.logging.log4j.core;
18  
19  import java.util.Collections;
20  import java.util.Map;
21  
22  import org.apache.logging.log4j.Level;
23  import org.apache.logging.log4j.Marker;
24  import org.apache.logging.log4j.ThreadContext;
25  import org.apache.logging.log4j.ThreadContext.ContextStack;
26  import org.apache.logging.log4j.core.impl.ThrowableProxy;
27  import org.apache.logging.log4j.core.time.Instant;
28  import org.apache.logging.log4j.core.time.MutableInstant;
29  import org.apache.logging.log4j.message.Message;
30  import org.apache.logging.log4j.util.ReadOnlyStringMap;
31  
32  
33  /**
34   * An abstract log event implementation with default values for all methods. The setters are no-ops.
35   */
36  public abstract class AbstractLogEvent implements LogEvent {
37  
38      private static final long serialVersionUID = 1L;
39  
40      private volatile MutableInstant instant;
41  
42      /**
43       * Subclasses should implement this method to provide an immutable version.
44       */
45      @Override
46      public LogEvent toImmutable() {
47          return this;
48      }
49  
50      @Override
51      public ReadOnlyStringMap getContextData() {
52          return null;
53      }
54  
55      /**
56       * Returns {@link Collections#emptyMap()}.
57       */
58      @Override
59      public Map<String, String> getContextMap() {
60          return Collections.emptyMap();
61      }
62  
63      @Override
64      public ContextStack getContextStack() {
65          return ThreadContext.EMPTY_STACK;
66      }
67  
68      @Override
69      public Level getLevel() {
70          return null;
71      }
72  
73      @Override
74      public String getLoggerFqcn() {
75          return null;
76      }
77  
78      @Override
79      public String getLoggerName() {
80          return null;
81      }
82  
83      @Override
84      public Marker getMarker() {
85          return null;
86      }
87  
88      @Override
89      public Message getMessage() {
90          return null;
91      }
92  
93      @Override
94      public StackTraceElement getSource() {
95          return null;
96      }
97  
98      @Override
99      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 }