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