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