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 LogEventJsonMixIn 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 = MapSerializer.class)
52  //    @JsonDeserialize(using = MapDeserializer.class)
53      @Override
54      @JsonIgnore
55  //    @JsonProperty(JsonConstants.ELT_CONTEXT_MAP)
56  //    @JacksonXmlProperty(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_CONTEXT_MAP)
57      public abstract Map<String, String> getContextMap();
58  
59      @JsonProperty(JsonConstants.ELT_CONTEXT_MAP)
60      @JacksonXmlProperty(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_CONTEXT_MAP)
61      @JsonSerialize(using = ContextDataSerializer.class)
62      @JsonDeserialize(using = ContextDataDeserializer.class)
63      //@JsonIgnore
64      @Override
65      public abstract ReadOnlyStringMap getContextData();
66  
67      @JsonProperty(JsonConstants.ELT_CONTEXT_STACK)
68      @JacksonXmlElementWrapper(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_CONTEXT_STACK)
69      @JacksonXmlProperty(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_CONTEXT_STACK_ITEM)
70      @Override
71      public abstract ContextStack getContextStack();
72  
73      @JsonProperty()
74      @JacksonXmlProperty(isAttribute = true)
75      @Override
76      public abstract Level getLevel();
77  
78      @JsonProperty()
79      @JacksonXmlProperty(isAttribute = true)
80      @Override
81      public abstract String getLoggerFqcn();
82  
83      @JsonProperty()
84      @JacksonXmlProperty(isAttribute = true)
85      @Override
86      public abstract String getLoggerName();
87  
88      @JsonProperty(JsonConstants.ELT_MARKER)
89      @JacksonXmlProperty(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_MARKER)
90      @Override
91      public abstract Marker getMarker();
92  
93      @JsonProperty(JsonConstants.ELT_MESSAGE)
94      @JsonSerialize(using = MessageSerializer.class)
95      @JsonDeserialize(using = SimpleMessageDeserializer.class)
96      @JacksonXmlProperty(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_MESSAGE)
97      @Override
98      public abstract Message getMessage();
99  
100     @JsonProperty(JsonConstants.ELT_SOURCE)
101     @JsonDeserialize(using = Log4jStackTraceElementDeserializer.class)
102     @JacksonXmlProperty(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_SOURCE)
103     @Override
104     public abstract StackTraceElement getSource();
105 
106     @Override
107     @JsonProperty("threadId")
108     @JacksonXmlProperty(isAttribute = true, localName = "threadId")
109     public abstract long getThreadId();
110 
111     @Override
112     @JsonProperty("thread")
113     @JacksonXmlProperty(isAttribute = true, localName = "thread")
114     public abstract String getThreadName();
115 
116     @Override
117     @JsonProperty("threadPriority")
118     @JacksonXmlProperty(isAttribute = true, localName = "threadPriority")
119     public abstract int getThreadPriority();
120 
121     @JsonIgnore
122     @Override
123     public abstract Throwable getThrown();
124 
125     @JsonProperty(JsonConstants.ELT_THROWN)
126     @JacksonXmlProperty(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_THROWN)
127     @Override
128     public abstract ThrowableProxy getThrownProxy();
129 
130     @JsonProperty()
131     @JacksonXmlProperty(isAttribute = true)
132     @Override
133     public abstract long getTimeMillis();
134 
135     @JsonProperty()
136     @JacksonXmlProperty(isAttribute = true)
137     @Override
138     public abstract boolean isEndOfBatch();
139 
140     @JsonIgnore
141     @Override
142     public abstract boolean isIncludeLocation();
143 
144     @Override
145     public abstract void setEndOfBatch(boolean endOfBatch);
146 
147     @Override
148     public abstract void setIncludeLocation(boolean locationRequired);
149 
150 }