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 LogEventJsonMixIn 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 = MapSerializer.class)
53  //    @JsonDeserialize(using = MapDeserializer.class)
54      @Override
55      @JsonIgnore
56  //    @JsonProperty(JsonConstants.ELT_CONTEXT_MAP)
57  //    @JacksonXmlProperty(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_CONTEXT_MAP)
58      public abstract Map<String, String> getContextMap();
59  
60      @JsonProperty(JsonConstants.ELT_CONTEXT_MAP)
61      @JacksonXmlProperty(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_CONTEXT_MAP)
62      @JsonSerialize(using = ContextDataSerializer.class)
63      @JsonDeserialize(using = ContextDataDeserializer.class)
64      //@JsonIgnore
65      @Override
66      public abstract ReadOnlyStringMap getContextData();
67  
68      @JsonProperty(JsonConstants.ELT_CONTEXT_STACK)
69      @JacksonXmlElementWrapper(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_CONTEXT_STACK)
70      @JacksonXmlProperty(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_CONTEXT_STACK_ITEM)
71      @Override
72      public abstract ContextStack getContextStack();
73  
74      @JsonProperty()
75      @JacksonXmlProperty(isAttribute = true)
76      @Override
77      public abstract Level getLevel();
78  
79      @JsonProperty()
80      @JacksonXmlProperty(isAttribute = true)
81      @Override
82      public abstract String getLoggerFqcn();
83  
84      @JsonProperty()
85      @JacksonXmlProperty(isAttribute = true)
86      @Override
87      public abstract String getLoggerName();
88  
89      @JsonProperty(JsonConstants.ELT_MARKER)
90      @JacksonXmlProperty(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_MARKER)
91      @Override
92      public abstract Marker getMarker();
93  
94      @JsonProperty(JsonConstants.ELT_MESSAGE)
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     @JsonIgnore // ignore from 2.11
131 //    @JsonProperty()
132 //    @JacksonXmlProperty(isAttribute = true)
133     @Override
134     public abstract long getTimeMillis();
135 
136     @JsonProperty(JsonConstants.ELT_INSTANT)
137     @JacksonXmlProperty(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_INSTANT)
138     @Override
139     public abstract Instant getInstant();
140 
141     @JsonProperty()
142     @JacksonXmlProperty(isAttribute = true)
143     @Override
144     public abstract boolean isEndOfBatch();
145 
146     @JsonIgnore
147     @Override
148     public abstract boolean isIncludeLocation();
149 
150     @Override
151     public abstract void setEndOfBatch(boolean endOfBatch);
152 
153     @Override
154     public abstract void setIncludeLocation(boolean locationRequired);
155 
156 }