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.jackson;
18  
19  import java.util.Map;
20  
21  import org.apache.logging.log4j.Level;
22  import org.apache.logging.log4j.Marker;
23  import org.apache.logging.log4j.ThreadContext.ContextStack;
24  import org.apache.logging.log4j.core.time.Instant;
25  import org.apache.logging.log4j.util.ReadOnlyStringMap;
26  import org.apache.logging.log4j.core.LogEvent;
27  import org.apache.logging.log4j.core.impl.ThrowableProxy;
28  import org.apache.logging.log4j.message.Message;
29  
30  import com.fasterxml.jackson.annotation.JsonFilter;
31  import com.fasterxml.jackson.annotation.JsonIgnore;
32  import com.fasterxml.jackson.annotation.JsonProperty;
33  import com.fasterxml.jackson.annotation.JsonPropertyOrder;
34  import com.fasterxml.jackson.annotation.JsonRootName;
35  import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
36  import com.fasterxml.jackson.databind.annotation.JsonSerialize;
37  import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
38  import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
39  import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
40  
41  @JsonRootName(XmlConstants.ELT_EVENT)
42  @JacksonXmlRootElement(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_EVENT)
43  @JsonFilter("org.apache.logging.log4j.core.impl.Log4jLogEvent")
44  @JsonPropertyOrder({ "timeMillis", XmlConstants.ELT_INSTANT, "threadName", "level", "loggerName", "marker", "message", "thrown", XmlConstants.ELT_CONTEXT_MAP,
45          JsonConstants.ELT_CONTEXT_STACK, "loggerFQCN", "Source", "endOfBatch" })
46  abstract class LogEventWithContextListMixIn implements LogEvent {
47  
48      private static final long serialVersionUID = 1L;
49  
50  //    @JsonProperty(JsonConstants.ELT_CONTEXT_MAP)
51  //    @JacksonXmlProperty(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_CONTEXT_MAP)
52  //    @JsonSerialize(using = ListOfMapEntrySerializer.class)
53  //    @JsonDeserialize(using = ListOfMapEntryDeserializer.class)
54      @Override
55      @JsonIgnore
56      public abstract Map<String, String> getContextMap();
57  
58      @JsonProperty(JsonConstants.ELT_CONTEXT_MAP)
59      @JacksonXmlProperty(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_CONTEXT_MAP)
60      @JsonSerialize(using = ContextDataAsEntryListSerializer.class)
61      @JsonDeserialize(using = ContextDataAsEntryListDeserializer.class)
62  //    @JsonIgnore
63      @Override
64      public abstract ReadOnlyStringMap getContextData();
65  
66      @JsonProperty(JsonConstants.ELT_CONTEXT_STACK)
67      @JacksonXmlElementWrapper(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_CONTEXT_STACK)
68      @JacksonXmlProperty(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_CONTEXT_STACK_ITEM)
69      @Override
70      public abstract ContextStack getContextStack();
71  
72      @JsonProperty()
73      @JacksonXmlProperty(isAttribute = true)
74      @Override
75      public abstract Level getLevel();
76  
77      @JsonProperty()
78      @JacksonXmlProperty(isAttribute = true)
79      @Override
80      public abstract String getLoggerFqcn();
81  
82      @JsonProperty()
83      @JacksonXmlProperty(isAttribute = true)
84      @Override
85      public abstract String getLoggerName();
86  
87      @JsonProperty(JsonConstants.ELT_MARKER)
88      @JacksonXmlProperty(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_MARKER)
89      @Override
90      public abstract Marker getMarker();
91  
92      @JsonProperty(JsonConstants.ELT_MESSAGE)
93      @JsonSerialize(using = MessageSerializer.class)
94      @JsonDeserialize(using = SimpleMessageDeserializer.class)
95      @JacksonXmlProperty(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_MESSAGE)
96      @Override
97      public abstract Message getMessage();
98  
99      @JsonProperty(JsonConstants.ELT_SOURCE)
100     @JsonDeserialize(using = Log4jStackTraceElementDeserializer.class)
101     @JacksonXmlProperty(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_SOURCE)
102     @Override
103     public abstract StackTraceElement getSource();
104 
105     @Override
106     @JsonProperty("threadId")
107     @JacksonXmlProperty(isAttribute = true, localName = "threadId")
108     public abstract long getThreadId();
109 
110     @Override
111     @JsonProperty("thread")
112     @JacksonXmlProperty(isAttribute = true, localName = "thread")
113     public abstract String getThreadName();
114 
115     @Override
116     @JsonProperty("threadPriority")
117     @JacksonXmlProperty(isAttribute = true, localName = "threadPriority")
118     public abstract int getThreadPriority();
119 
120     @JsonIgnore
121     @Override
122     public abstract Throwable getThrown();
123 
124     @JsonProperty(JsonConstants.ELT_THROWN)
125     @JacksonXmlProperty(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_THROWN)
126     @Override
127     public abstract ThrowableProxy getThrownProxy();
128 
129     @JsonIgnore // ignore from 2.11
130 //    @JsonProperty()
131 //    @JacksonXmlProperty(isAttribute = true)
132     @Override
133     public abstract long getTimeMillis();
134 
135     @JsonProperty(JsonConstants.ELT_INSTANT)
136     @JacksonXmlProperty(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_INSTANT)
137     @Override
138     public abstract Instant getInstant();
139 
140     @JsonProperty()
141     @JacksonXmlProperty(isAttribute = true)
142     @Override
143     public abstract boolean isEndOfBatch();
144 
145     @JsonIgnore
146     @Override
147     public abstract boolean isIncludeLocation();
148 
149     @Override
150     public abstract void setEndOfBatch(boolean endOfBatch);
151 
152     @Override
153     public abstract void setIncludeLocation(boolean locationRequired);
154 
155 }