http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0eb5212e/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/MapEntry.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/MapEntry.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/MapEntry.java deleted file mode 100644 index 239b084..0000000 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/MapEntry.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache license, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the license for the specific language governing permissions and - * limitations under the license. - */ -package org.apache.logging.log4j.core.jackson; - -import org.apache.logging.log4j.util.Strings; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; - -/** - * <p> - * <em>Consider this class private.</em> - * </p> - * <p> - * Used to represent map entries in a generic fashion because the default Jackson behavior uses the key as the element tag. Using the key as - * an element/property name would mean that you cannot have a generic JSON/XML schema for all log event. - * </p> - */ -@JsonPropertyOrder({ "key", "value" }) -final class MapEntry { - - @JsonProperty - @JacksonXmlProperty(isAttribute = true) - private String key; - - @JsonProperty - @JacksonXmlProperty(isAttribute = true) - private String value; - - @JsonCreator - public MapEntry(@JsonProperty("key") final String key, @JsonProperty("value") final String value) { - this.setKey(key); - this.setValue(value); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (!(obj instanceof MapEntry)) { - return false; - } - final MapEntry other = (MapEntry) obj; - if (this.getKey() == null) { - if (other.getKey() != null) { - return false; - } - } else if (!this.getKey().equals(other.getKey())) { - return false; - } - if (this.getValue() == null) { - if (other.getValue() != null) { - return false; - } - } else if (!this.getValue().equals(other.getValue())) { - return false; - } - return true; - } - - public String getKey() { - return this.key; - } - - public String getValue() { - return this.value; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((this.getKey() == null) ? 0 : this.getKey().hashCode()); - result = prime * result + ((this.getValue() == null) ? 0 : this.getValue().hashCode()); - return result; - } - - public void setKey(final String key) { - this.key = key; - } - - public void setValue(final String value) { - this.value = value; - } - - @Override - public String toString() { - return Strings.EMPTY + this.getKey() + "=" + this.getValue(); - } -} \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0eb5212e/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/MarkerMixIn.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/MarkerMixIn.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/MarkerMixIn.java deleted file mode 100644 index 950c2c8..0000000 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/MarkerMixIn.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache license, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the license for the specific language governing permissions and - * limitations under the license. - */ -package org.apache.logging.log4j.core.jackson; - -import org.apache.logging.log4j.Marker; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; - -/** - * Jackson mix-in for {@link Marker}. - * <p> - * If we want to deal with more than one {@link Marker} implementation then recode these annotations to include metadata. - * </p> - * <p> - * <em>Consider this class private.</em> - * </p> - * <p> - * Example XML: - * </p> - * <pre> -<Marker name="Marker1"> - <Parents> - <Marker name="ParentMarker1"> - <Parents> - <Marker name="GrandMotherMarker"/> - <Marker name="GrandFatherMarker"/> - </Parents> - </Marker> - <Marker name="ParentMarker2"/> - </Parents> -</Marker> - * </pre> - * - * @see Marker - */ -// Alternate for multiple Marker implementation. -// @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "@class") -@JsonDeserialize(as = org.apache.logging.log4j.MarkerManager.Log4jMarker.class) -abstract class MarkerMixIn implements Marker { - private static final long serialVersionUID = 1L; - - @JsonCreator - MarkerMixIn(@JsonProperty("name") final String name) { - // empty - } - - @Override - @JsonProperty("name") - @JacksonXmlProperty(isAttribute = true) - public abstract String getName(); - - @Override - @JsonProperty(JsonConstants.ELT_PARENTS) - @JacksonXmlElementWrapper(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_PARENTS) - @JacksonXmlProperty(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_MARKER) - public abstract Marker[] getParents(); - -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0eb5212e/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/MessageSerializer.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/MessageSerializer.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/MessageSerializer.java deleted file mode 100644 index 3c19672..0000000 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/MessageSerializer.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache license, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the license for the specific language governing permissions and - * limitations under the license. - */ -package org.apache.logging.log4j.core.jackson; - -import java.io.IOException; - -import org.apache.logging.log4j.message.Message; - -import com.fasterxml.jackson.core.JsonGenerationException; -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.ser.std.StdScalarSerializer; - -/** - * <p> - * <em>Consider this class private.</em> - * </p> - */ -final class MessageSerializer extends StdScalarSerializer<Message> { - - private static final long serialVersionUID = 1L; - - MessageSerializer() { - super(Message.class); - } - - @Override - public void serialize(final Message value, final JsonGenerator jgen, final SerializerProvider provider) throws IOException, - JsonGenerationException { - jgen.writeString(value.getFormattedMessage()); - } - -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0eb5212e/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/MutableThreadContextStackDeserializer.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/MutableThreadContextStackDeserializer.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/MutableThreadContextStackDeserializer.java deleted file mode 100644 index 4d4a530..0000000 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/MutableThreadContextStackDeserializer.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache license, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the license for the specific language governing permissions and - * limitations under the license. - */ -package org.apache.logging.log4j.core.jackson; - -import java.io.IOException; -import java.util.List; - -import org.apache.logging.log4j.spi.MutableThreadContextStack; - -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.deser.std.StdDeserializer; - -/** - * <p> - * <em>Consider this class private.</em> - * </p> - */ -final class MutableThreadContextStackDeserializer extends StdDeserializer<MutableThreadContextStack> { - - private static final long serialVersionUID = 1L; - - MutableThreadContextStackDeserializer() { - super(MutableThreadContextStack.class); - } - - @Override - public MutableThreadContextStack deserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException, - JsonProcessingException { - final List<String> list = jp.readValueAs(new TypeReference<List<String>>() { - // empty - }); - return new MutableThreadContextStack(list); - } -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0eb5212e/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ObjectMessageSerializer.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ObjectMessageSerializer.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ObjectMessageSerializer.java deleted file mode 100644 index 8bbfe0b..0000000 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ObjectMessageSerializer.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache license, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the license for the specific language governing permissions and - * limitations under the license. - */ -package org.apache.logging.log4j.core.jackson; - -import java.io.IOException; - -import org.apache.logging.log4j.message.ObjectMessage; - -import com.fasterxml.jackson.core.JsonGenerationException; -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.ser.std.StdScalarSerializer; - -/** - * <p> - * <em>Consider this class private.</em> - * </p> - */ -final class ObjectMessageSerializer extends StdScalarSerializer<ObjectMessage> { - - private static final long serialVersionUID = 1L; - - ObjectMessageSerializer() { - super(ObjectMessage.class); - } - - @Override - public void serialize(final ObjectMessage value, final JsonGenerator jgen, final SerializerProvider provider) throws IOException, - JsonGenerationException { - jgen.writeObject(value.getParameter()); - } - -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0eb5212e/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/SimpleMessageDeserializer.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/SimpleMessageDeserializer.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/SimpleMessageDeserializer.java deleted file mode 100644 index f269590..0000000 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/SimpleMessageDeserializer.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache license, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the license for the specific language governing permissions and - * limitations under the license. - */ -package org.apache.logging.log4j.core.jackson; - -import java.io.IOException; - -import org.apache.logging.log4j.message.SimpleMessage; - -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.deser.std.StdScalarDeserializer; - -/** - * <p> - * <em>Consider this class private.</em> - * </p> - */ -public final class SimpleMessageDeserializer extends StdScalarDeserializer<SimpleMessage> { - - private static final long serialVersionUID = 1L; - - SimpleMessageDeserializer() { - super(SimpleMessage.class); - } - - @Override - public SimpleMessage deserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException, - JsonProcessingException { - return new SimpleMessage(jp.getValueAsString()); - } - -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0eb5212e/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/StackTraceElementMixIn.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/StackTraceElementMixIn.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/StackTraceElementMixIn.java deleted file mode 100644 index 9a3b022..0000000 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/StackTraceElementMixIn.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache license, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the license for the specific language governing permissions and - * limitations under the license. - */ -package org.apache.logging.log4j.core.jackson; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; - -/** - * Jackson mix-in for {@link StackTraceElement}. - * <p> - * <em>Consider this class private.</em> - * </p> - * - * @see StackTraceElement - */ -@JsonIgnoreProperties("nativeMethod") -abstract class StackTraceElementMixIn { - @JsonCreator - StackTraceElementMixIn( - // @formatter:off - @JsonProperty("class") final String declaringClass, - @JsonProperty("method") final String methodName, - @JsonProperty("file") final String fileName, - @JsonProperty("line") final int lineNumber) - // @formatter:on - { - // empty - } - - @JsonProperty("class") - @JacksonXmlProperty(localName = "class", isAttribute = true) - abstract String getClassName(); - - @JsonProperty("file") - @JacksonXmlProperty(localName = "file", isAttribute = true) - abstract String getFileName(); - - @JsonProperty("line") - @JacksonXmlProperty(localName = "line", isAttribute = true) - abstract int getLineNumber(); - - @JsonProperty("method") - @JacksonXmlProperty(localName = "method", isAttribute = true) - abstract String getMethodName(); - -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0eb5212e/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ThrowableProxyMixIn.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ThrowableProxyMixIn.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ThrowableProxyMixIn.java deleted file mode 100644 index a36c1b4..0000000 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ThrowableProxyMixIn.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache license, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the license for the specific language governing permissions and - * limitations under the license. - */ -package org.apache.logging.log4j.core.jackson; - -import org.apache.logging.log4j.core.impl.ExtendedStackTraceElement; -import org.apache.logging.log4j.core.impl.ThrowableProxy; - -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; - -/** - * Mix-in for {@link ThrowableProxy}. - */ -abstract class ThrowableProxyMixIn { - - @JsonProperty(JsonConstants.ELT_CAUSE) - @JacksonXmlProperty(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_CAUSE) - private ThrowableProxyMixIn causeProxy; - - @JsonProperty - @JacksonXmlProperty(isAttribute = true) - private int commonElementCount; - - @JsonProperty(JsonConstants.ELT_EXTENDED_STACK_TRACE) - @JacksonXmlElementWrapper(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_EXTENDED_STACK_TRACE) - @JacksonXmlProperty(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_EXTENDED_STACK_TRACE_ITEM) - private ExtendedStackTraceElement[] extendedStackTrace; - - @JsonProperty - @JacksonXmlProperty(isAttribute = true) - private String localizedMessage; - - @JsonProperty - @JacksonXmlProperty(isAttribute = true) - private String message; - - @JsonProperty - @JacksonXmlProperty(isAttribute = true) - private String name; - - @JsonIgnore - private transient Throwable throwable; - - @JsonIgnore - public abstract String getCauseStackTraceAsString(); - - @JsonIgnore - public abstract String getExtendedStackTraceAsString(); - - @JsonIgnore - public abstract StackTraceElement[] getStackTrace(); - - @JsonProperty(JsonConstants.ELT_SUPPRESSED) - @JacksonXmlElementWrapper(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_SUPPRESSED) - @JacksonXmlProperty(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_SUPPRESSED_ITEM) - public abstract ThrowableProxy[] getSuppressedProxies(); - - @JsonIgnore - public abstract String getSuppressedStackTrace(); - - @JsonIgnore - public abstract Throwable getThrowable(); - -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0eb5212e/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ThrowableProxyWithStacktraceAsStringMixIn.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ThrowableProxyWithStacktraceAsStringMixIn.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ThrowableProxyWithStacktraceAsStringMixIn.java deleted file mode 100644 index f169d35..0000000 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ThrowableProxyWithStacktraceAsStringMixIn.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache license, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the license for the specific language governing permissions and - * limitations under the license. - */ -package org.apache.logging.log4j.core.jackson; - -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; -import org.apache.logging.log4j.core.impl.ExtendedStackTraceElement; -import org.apache.logging.log4j.core.impl.ThrowableProxy; - -/** - * Mix-in for {@link org.apache.logging.log4j.core.impl.ThrowableProxy}. - */ -abstract class ThrowableProxyWithStacktraceAsStringMixIn { - - @JsonProperty(JsonConstants.ELT_CAUSE) - @JacksonXmlProperty(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_CAUSE) - private ThrowableProxyWithStacktraceAsStringMixIn causeProxy; - - @JsonProperty - @JacksonXmlProperty(isAttribute = true) - private int commonElementCount; - - @JsonIgnore - private ExtendedStackTraceElement[] extendedStackTrace; - - @JsonProperty - @JacksonXmlProperty(isAttribute = true) - private String localizedMessage; - - @JsonProperty - @JacksonXmlProperty(isAttribute = true) - private String message; - - @JsonProperty - @JacksonXmlProperty(isAttribute = true) - private String name; - - @JsonIgnore - private transient Throwable throwable; - - @JsonIgnore - public abstract String getCauseStackTraceAsString(); - - @JsonProperty(JsonConstants.ELT_EXTENDED_STACK_TRACE) - @JacksonXmlProperty(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_EXTENDED_STACK_TRACE) - public abstract String getExtendedStackTraceAsString(); - - @JsonIgnore - public abstract StackTraceElement[] getStackTrace(); - - @JsonProperty(JsonConstants.ELT_SUPPRESSED) - @JacksonXmlElementWrapper(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_SUPPRESSED) - @JacksonXmlProperty(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_SUPPRESSED_ITEM) - public abstract ThrowableProxy[] getSuppressedProxies(); - - @JsonIgnore - public abstract String getSuppressedStackTrace(); - - @JsonIgnore - public abstract Throwable getThrowable(); - -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0eb5212e/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ThrowableProxyWithoutStacktraceMixIn.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ThrowableProxyWithoutStacktraceMixIn.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ThrowableProxyWithoutStacktraceMixIn.java deleted file mode 100644 index 264bef8..0000000 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ThrowableProxyWithoutStacktraceMixIn.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache license, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the license for the specific language governing permissions and - * limitations under the license. - */ -package org.apache.logging.log4j.core.jackson; - -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; -import org.apache.logging.log4j.core.impl.ExtendedStackTraceElement; -import org.apache.logging.log4j.core.impl.ThrowableProxy; - -/** - * Mix-in for {@link ThrowableProxy}. - */ -abstract class ThrowableProxyWithoutStacktraceMixIn { - - @JsonProperty(JsonConstants.ELT_CAUSE) - @JacksonXmlProperty(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_CAUSE) - private ThrowableProxyWithoutStacktraceMixIn causeProxy; - - @JsonProperty - @JacksonXmlProperty(isAttribute = true) - private int commonElementCount; - - @JsonIgnore - private ExtendedStackTraceElement[] extendedStackTrace; - - @JsonProperty - @JacksonXmlProperty(isAttribute = true) - private String localizedMessage; - - @JsonProperty - @JacksonXmlProperty(isAttribute = true) - private String message; - - @JsonProperty - @JacksonXmlProperty(isAttribute = true) - private String name; - - @JsonIgnore - private transient Throwable throwable; - - @JsonIgnore - public abstract String getCauseStackTraceAsString(); - - @JsonIgnore - public abstract String getExtendedStackTraceAsString(); - - @JsonIgnore - public abstract StackTraceElement[] getStackTrace(); - - @JsonProperty(JsonConstants.ELT_SUPPRESSED) - @JacksonXmlElementWrapper(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_SUPPRESSED) - @JacksonXmlProperty(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_SUPPRESSED_ITEM) - public abstract ThrowableProxy[] getSuppressedProxies(); - - @JsonIgnore - public abstract String getSuppressedStackTrace(); - - @JsonIgnore - public abstract Throwable getThrowable(); - -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0eb5212e/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/XmlConstants.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/XmlConstants.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/XmlConstants.java deleted file mode 100644 index 0871440..0000000 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/XmlConstants.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache license, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the license for the specific language governing permissions and - * limitations under the license. - */ -package org.apache.logging.log4j.core.jackson; - -/** - * Keeps constants separate from any class that may depend on third party jars. - */ -public final class XmlConstants { - public static final String ELT_CAUSE = "Cause"; - public static final String ELT_CONTEXT_MAP = "ContextMap"; - public static final String ELT_CONTEXT_STACK = "ContextStack"; - public static final String ELT_CONTEXT_STACK_ITEM = "ContextStackItem"; - public static final String ELT_EVENT = "Event"; - public static final String ELT_EXTENDED_STACK_TRACE = "ExtendedStackTrace"; - public static final String ELT_EXTENDED_STACK_TRACE_ITEM = "ExtendedStackTraceItem"; - public static final String ELT_INSTANT = "Instant"; - public static final String ELT_MARKER = "Marker"; - public static final String ELT_MESSAGE = "Message"; - public static final String ELT_PARENTS = "Parents"; - public static final String ELT_SOURCE = "Source"; - public static final String ELT_SUPPRESSED = "Suppressed"; - public static final String ELT_SUPPRESSED_ITEM = "SuppressedItem"; - public static final String ELT_THROWN = "Thrown"; - public static final String XML_NAMESPACE = "http://logging.apache.org/log4j/2.0/events"; -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0eb5212e/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/package-info.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/package-info.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/package-info.java deleted file mode 100644 index 585da42..0000000 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/package-info.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache license, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the license for the specific language governing permissions and - * limitations under the license. - */ -/** - * Classes and interfaces for serializing and deserializing Log4j 2 log events to XML and JSON using the Jackson - * library. - */ -package org.apache.logging.log4j.core.jackson; http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0eb5212e/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractJacksonLayout.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractJacksonLayout.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractJacksonLayout.java deleted file mode 100644 index 7a04100..0000000 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractJacksonLayout.java +++ /dev/null @@ -1,350 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache license, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the license for the specific language governing permissions and - * limitations under the license. - */ -package org.apache.logging.log4j.core.layout; - -import java.io.IOException; -import java.io.Writer; -import java.nio.charset.Charset; -import java.util.LinkedHashMap; -import java.util.Map; - -import org.apache.logging.log4j.core.LogEvent; -import org.apache.logging.log4j.core.config.Configuration; -import org.apache.logging.log4j.core.config.plugins.PluginBuilderAttribute; -import org.apache.logging.log4j.core.config.plugins.PluginElement; -import org.apache.logging.log4j.core.impl.MutableLogEvent; -import org.apache.logging.log4j.core.jackson.XmlConstants; -import org.apache.logging.log4j.core.lookup.StrSubstitutor; -import org.apache.logging.log4j.core.util.KeyValuePair; -import org.apache.logging.log4j.core.util.StringBuilderWriter; -import org.apache.logging.log4j.util.Strings; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonRootName; -import com.fasterxml.jackson.annotation.JsonUnwrapped; -import com.fasterxml.jackson.core.JsonGenerationException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectWriter; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; - -abstract class AbstractJacksonLayout extends AbstractStringLayout { - - protected static final String DEFAULT_EOL = "\r\n"; - protected static final String COMPACT_EOL = Strings.EMPTY; - - public static abstract class Builder<B extends Builder<B>> extends AbstractStringLayout.Builder<B> { - - @PluginBuilderAttribute - private boolean eventEol; - - @PluginBuilderAttribute - private boolean compact; - - @PluginBuilderAttribute - private boolean complete; - - @PluginBuilderAttribute - private boolean locationInfo; - - @PluginBuilderAttribute - private boolean properties; - - @PluginBuilderAttribute - private boolean includeStacktrace = true; - - @PluginBuilderAttribute - private boolean stacktraceAsString = false; - - @PluginBuilderAttribute - private boolean includeNullDelimiter = false; - - @PluginElement("AdditionalField") - private KeyValuePair[] additionalFields; - - protected String toStringOrNull(final byte[] header) { - return header == null ? null : new String(header, Charset.defaultCharset()); - } - - public boolean getEventEol() { - return eventEol; - } - - public boolean isCompact() { - return compact; - } - - public boolean isComplete() { - return complete; - } - - public boolean isLocationInfo() { - return locationInfo; - } - - public boolean isProperties() { - return properties; - } - - /** - * If "true", includes the stacktrace of any Throwable in the generated data, defaults to "true". - * @return If "true", includes the stacktrace of any Throwable in the generated data, defaults to "true". - */ - public boolean isIncludeStacktrace() { - return includeStacktrace; - } - - public boolean isStacktraceAsString() { - return stacktraceAsString; - } - - public boolean isIncludeNullDelimiter() { return includeNullDelimiter; } - - public KeyValuePair[] getAdditionalFields() { - return additionalFields; - } - - public B setEventEol(final boolean eventEol) { - this.eventEol = eventEol; - return asBuilder(); - } - - public B setCompact(final boolean compact) { - this.compact = compact; - return asBuilder(); - } - - public B setComplete(final boolean complete) { - this.complete = complete; - return asBuilder(); - } - - public B setLocationInfo(final boolean locationInfo) { - this.locationInfo = locationInfo; - return asBuilder(); - } - - public B setProperties(final boolean properties) { - this.properties = properties; - return asBuilder(); - } - - /** - * If "true", includes the stacktrace of any Throwable in the generated JSON, defaults to "true". - * @param includeStacktrace If "true", includes the stacktrace of any Throwable in the generated JSON, defaults to "true". - * @return this builder - */ - public B setIncludeStacktrace(final boolean includeStacktrace) { - this.includeStacktrace = includeStacktrace; - return asBuilder(); - } - - /** - * Whether to format the stacktrace as a string, and not a nested object (optional, defaults to false). - * - * @return this builder - */ - public B setStacktraceAsString(final boolean stacktraceAsString) { - this.stacktraceAsString = stacktraceAsString; - return asBuilder(); - } - - /** - * Whether to include NULL byte as delimiter after each event (optional, default to false). - * - * @return this builder - */ - public B setIncludeNullDelimiter(final boolean includeNullDelimiter) { - this.includeNullDelimiter = includeNullDelimiter; - return asBuilder(); - } - - /** - * Additional fields to set on each log event. - * - * @return this builder - */ - public B setAdditionalFields(KeyValuePair[] additionalFields) { - this.additionalFields = additionalFields; - return asBuilder(); - } - } - - protected final String eol; - protected final ObjectWriter objectWriter; - protected final boolean compact; - protected final boolean complete; - protected final boolean includeNullDelimiter; - protected final ResolvableKeyValuePair[] additionalFields; - - @Deprecated - protected AbstractJacksonLayout(final Configuration config, final ObjectWriter objectWriter, final Charset charset, - final boolean compact, final boolean complete, final boolean eventEol, final Serializer headerSerializer, - final Serializer footerSerializer) { - this(config, objectWriter, charset, compact, complete, eventEol, headerSerializer, footerSerializer, false); - } - - @Deprecated - protected AbstractJacksonLayout(final Configuration config, final ObjectWriter objectWriter, final Charset charset, - final boolean compact, final boolean complete, final boolean eventEol, final Serializer headerSerializer, - final Serializer footerSerializer, final boolean includeNullDelimiter) { - this(config, objectWriter, charset, compact, complete, eventEol, headerSerializer, footerSerializer, includeNullDelimiter, null); - } - - protected AbstractJacksonLayout(final Configuration config, final ObjectWriter objectWriter, final Charset charset, - final boolean compact, final boolean complete, final boolean eventEol, final Serializer headerSerializer, - final Serializer footerSerializer, final boolean includeNullDelimiter, - final KeyValuePair[] additionalFields) { - super(config, charset, headerSerializer, footerSerializer); - this.objectWriter = objectWriter; - this.compact = compact; - this.complete = complete; - this.eol = compact && !eventEol ? COMPACT_EOL : DEFAULT_EOL; - this.includeNullDelimiter = includeNullDelimiter; - this.additionalFields = prepareAdditionalFields(config, additionalFields); - } - - protected static boolean valueNeedsLookup(final String value) { - return value != null && value.contains("${"); - } - - private static ResolvableKeyValuePair[] prepareAdditionalFields(final Configuration config, final KeyValuePair[] additionalFields) { - if (additionalFields == null || additionalFields.length == 0) { - // No fields set - return new ResolvableKeyValuePair[0]; - } - - // Convert to specific class which already determines whether values needs lookup during serialization - final ResolvableKeyValuePair[] resolvableFields = new ResolvableKeyValuePair[additionalFields.length]; - - for (int i = 0; i < additionalFields.length; i++) { - ResolvableKeyValuePair resolvable = resolvableFields[i] = new ResolvableKeyValuePair(additionalFields[i]); - - // Validate - if (config == null && resolvable.valueNeedsLookup) { - throw new IllegalArgumentException("configuration needs to be set when there are additional fields with variables"); - } - } - - return resolvableFields; - } - - /** - * Formats a {@link org.apache.logging.log4j.core.LogEvent}. - * - * @param event The LogEvent. - * @return The XML representation of the LogEvent. - */ - @Override - public String toSerializable(final LogEvent event) { - final StringBuilderWriter writer = new StringBuilderWriter(); - try { - toSerializable(event, writer); - return writer.toString(); - } catch (final IOException e) { - // Should this be an ISE or IAE? - LOGGER.error(e); - return Strings.EMPTY; - } - } - - private static LogEvent convertMutableToLog4jEvent(final LogEvent event) { - // TODO Jackson-based layouts have certain filters set up for Log4jLogEvent. - // TODO Need to set up the same filters for MutableLogEvent but don't know how... - // This is a workaround. - return event instanceof MutableLogEvent - ? ((MutableLogEvent) event).createMemento() - : event; - } - - protected Object wrapLogEvent(final LogEvent event) { - if (additionalFields.length > 0) { - // Construct map for serialization - note that we are intentionally using original LogEvent - Map<String, String> additionalFieldsMap = resolveAdditionalFields(event); - // This class combines LogEvent with AdditionalFields during serialization - return new LogEventWithAdditionalFields(event, additionalFieldsMap); - } else { - // No additional fields, return original object - return event; - } - } - - private Map<String, String> resolveAdditionalFields(LogEvent logEvent) { - // Note: LinkedHashMap retains order - final Map<String, String> additionalFieldsMap = new LinkedHashMap<>(additionalFields.length); - final StrSubstitutor strSubstitutor = configuration.getStrSubstitutor(); - - // Go over each field - for (ResolvableKeyValuePair pair : additionalFields) { - if (pair.valueNeedsLookup) { - // Resolve value - additionalFieldsMap.put(pair.key, strSubstitutor.replace(logEvent, pair.value)); - } else { - // Plain text value - additionalFieldsMap.put(pair.key, pair.value); - } - } - - return additionalFieldsMap; - } - - public void toSerializable(final LogEvent event, final Writer writer) - throws JsonGenerationException, JsonMappingException, IOException { - objectWriter.writeValue(writer, wrapLogEvent(convertMutableToLog4jEvent(event))); - writer.write(eol); - if (includeNullDelimiter) { - writer.write('\0'); - } - markEvent(); - } - - @JsonRootName(XmlConstants.ELT_EVENT) - @JacksonXmlRootElement(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_EVENT) - public static class LogEventWithAdditionalFields { - - private final Object logEvent; - private final Map<String, String> additionalFields; - - public LogEventWithAdditionalFields(Object logEvent, Map<String, String> additionalFields) { - this.logEvent = logEvent; - this.additionalFields = additionalFields; - } - - @JsonUnwrapped - public Object getLogEvent() { - return logEvent; - } - - @JsonAnyGetter - @SuppressWarnings("unused") - public Map<String, String> getAdditionalFields() { - return additionalFields; - } - } - - protected static class ResolvableKeyValuePair { - - final String key; - final String value; - final boolean valueNeedsLookup; - - ResolvableKeyValuePair(KeyValuePair pair) { - this.key = pair.getKey(); - this.value = pair.getValue(); - this.valueNeedsLookup = AbstractJacksonLayout.valueNeedsLookup(this.value); - } - } -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0eb5212e/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/GelfLayout.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/GelfLayout.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/GelfLayout.java index 45c5f4f..7f01f8e 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/GelfLayout.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/GelfLayout.java @@ -294,7 +294,7 @@ public final class GelfLayout extends AbstractStringLayout { @Override public String getContentType() { - return JsonLayout.CONTENT_TYPE + "; charset=" + this.getCharset(); + return "application/json; charset=" + this.getCharset(); } @Override http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0eb5212e/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JacksonFactory.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JacksonFactory.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JacksonFactory.java deleted file mode 100644 index b4c914c..0000000 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JacksonFactory.java +++ /dev/null @@ -1,237 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache license, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the license for the specific language governing permissions and - * limitations under the license. - */ -package org.apache.logging.log4j.core.layout; - -import java.util.HashSet; -import java.util.Set; - -import javax.xml.stream.XMLStreamException; - -import org.apache.logging.log4j.core.impl.Log4jLogEvent; -import org.apache.logging.log4j.core.jackson.JsonConstants; -import org.apache.logging.log4j.core.jackson.Log4jJsonObjectMapper; -import org.apache.logging.log4j.core.jackson.Log4jXmlObjectMapper; -import org.apache.logging.log4j.core.jackson.Log4jYamlObjectMapper; -import org.apache.logging.log4j.core.jackson.XmlConstants; -import org.codehaus.stax2.XMLStreamWriter2; - -import com.fasterxml.jackson.core.PrettyPrinter; -import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; -import com.fasterxml.jackson.core.util.MinimalPrettyPrinter; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.ObjectWriter; -import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter; -import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider; -import com.fasterxml.jackson.dataformat.xml.util.DefaultXmlPrettyPrinter; - -abstract class JacksonFactory { - - static class JSON extends JacksonFactory { - - private final boolean encodeThreadContextAsList; - private final boolean includeStacktrace; - private final boolean stacktraceAsString; - private final boolean objectMessageAsJsonObject; - - public JSON(final boolean encodeThreadContextAsList, final boolean includeStacktrace, final boolean stacktraceAsString, final boolean objectMessageAsJsonObject) { - this.encodeThreadContextAsList = encodeThreadContextAsList; - this.includeStacktrace = includeStacktrace; - this.stacktraceAsString = stacktraceAsString; - this.objectMessageAsJsonObject = objectMessageAsJsonObject; - } - - @Override - protected String getPropertNameForContextMap() { - return JsonConstants.ELT_CONTEXT_MAP; - } - - @Override - protected String getPropertNameForSource() { - return JsonConstants.ELT_SOURCE; - } - - @Override - protected String getPropertNameForNanoTime() { - return JsonConstants.ELT_NANO_TIME; - } - - @Override - protected PrettyPrinter newCompactPrinter() { - return new MinimalPrettyPrinter(); - } - - @Override - protected ObjectMapper newObjectMapper() { - return new Log4jJsonObjectMapper(encodeThreadContextAsList, includeStacktrace, stacktraceAsString, objectMessageAsJsonObject); - } - - @Override - protected PrettyPrinter newPrettyPrinter() { - return new DefaultPrettyPrinter(); - } - - } - - static class XML extends JacksonFactory { - - static final int DEFAULT_INDENT = 1; - - private final boolean includeStacktrace; - private final boolean stacktraceAsString; - - - public XML(final boolean includeStacktrace, final boolean stacktraceAsString) { - this.includeStacktrace = includeStacktrace; - this.stacktraceAsString = stacktraceAsString; - } - - @Override - protected String getPropertNameForContextMap() { - return XmlConstants.ELT_CONTEXT_MAP; - } - - @Override - protected String getPropertNameForSource() { - return XmlConstants.ELT_SOURCE; - } - - @Override - protected String getPropertNameForNanoTime() { - return JsonConstants.ELT_NANO_TIME; - } - - @Override - protected PrettyPrinter newCompactPrinter() { - // Yes, null is the proper answer. - return null; - } - - @Override - protected ObjectMapper newObjectMapper() { - return new Log4jXmlObjectMapper(includeStacktrace, stacktraceAsString); - } - - @Override - protected PrettyPrinter newPrettyPrinter() { - return new Log4jXmlPrettyPrinter(DEFAULT_INDENT); - } - } - - static class YAML extends JacksonFactory { - - private final boolean includeStacktrace; - private final boolean stacktraceAsString; - - - public YAML(final boolean includeStacktrace, final boolean stacktraceAsString) { - this.includeStacktrace = includeStacktrace; - this.stacktraceAsString = stacktraceAsString; - } - - @Override - protected String getPropertNameForContextMap() { - return JsonConstants.ELT_CONTEXT_MAP; - } - - @Override - protected String getPropertNameForSource() { - return JsonConstants.ELT_SOURCE; - } - - @Override - protected String getPropertNameForNanoTime() { - return JsonConstants.ELT_NANO_TIME; - } - - @Override - protected PrettyPrinter newCompactPrinter() { - return new MinimalPrettyPrinter(); - } - - @Override - protected ObjectMapper newObjectMapper() { - return new Log4jYamlObjectMapper(false, includeStacktrace, stacktraceAsString); - } - - @Override - protected PrettyPrinter newPrettyPrinter() { - return new DefaultPrettyPrinter(); - } - } - - /** - * When <Event>s are written into a XML file; the "Event" object is not the root element, but an element named - * <Events> created using {@link XmlLayout#getHeader()} and {@link XmlLayout#getFooter()} methods. - * <p> - * {@link com.fasterxml.jackson.dataformat.xml.util.DefaultXmlPrettyPrinter} is used to print the Event object into - * XML; hence it assumes <Event> tag as the root element, so it prints the <Event> tag without any - * indentation. To add an indentation to the <Event> tag; hence an additional indentation for any - * sub-elements, this class is written. As an additional task, to avoid the blank line printed after the ending - * </Event> tag, {@link #writePrologLinefeed(XMLStreamWriter2)} method is also overridden. - * </p> - */ - static class Log4jXmlPrettyPrinter extends DefaultXmlPrettyPrinter { - - private static final long serialVersionUID = 1L; - - Log4jXmlPrettyPrinter(final int nesting) { - _nesting = nesting; - } - - @Override - public void writePrologLinefeed(final XMLStreamWriter2 sw) throws XMLStreamException { - // nothing - } - - /** - * Sets the nesting level to 1 rather than 0, so the "Event" tag will get indentation of next level below root. - */ - @Override - public DefaultXmlPrettyPrinter createInstance() { - return new Log4jXmlPrettyPrinter(XML.DEFAULT_INDENT); - } - - } - - abstract protected String getPropertNameForContextMap(); - - abstract protected String getPropertNameForSource(); - - abstract protected String getPropertNameForNanoTime(); - - abstract protected PrettyPrinter newCompactPrinter(); - - abstract protected ObjectMapper newObjectMapper(); - - abstract protected PrettyPrinter newPrettyPrinter(); - - ObjectWriter newWriter(final boolean locationInfo, final boolean properties, final boolean compact) { - final SimpleFilterProvider filters = new SimpleFilterProvider(); - final Set<String> except = new HashSet<>(2); - if (!locationInfo) { - except.add(this.getPropertNameForSource()); - } - if (!properties) { - except.add(this.getPropertNameForContextMap()); - } - except.add(this.getPropertNameForNanoTime()); - filters.addFilter(Log4jLogEvent.class.getName(), SimpleBeanPropertyFilter.serializeAllExcept(except)); - final ObjectWriter writer = this.newObjectMapper().writer(compact ? this.newCompactPrinter() : this.newPrettyPrinter()); - return writer.with(filters); - } - -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0eb5212e/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JsonLayout.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JsonLayout.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JsonLayout.java deleted file mode 100644 index 607ec43..0000000 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JsonLayout.java +++ /dev/null @@ -1,293 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache license, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the license for the specific language governing permissions and - * limitations under the license. - */ -package org.apache.logging.log4j.core.layout; - -import java.io.IOException; -import java.io.Writer; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.util.HashMap; -import java.util.Map; - -import org.apache.logging.log4j.core.Layout; -import org.apache.logging.log4j.core.LogEvent; -import org.apache.logging.log4j.core.config.Configuration; -import org.apache.logging.log4j.core.config.DefaultConfiguration; -import org.apache.logging.log4j.core.config.Node; -import org.apache.logging.log4j.core.config.plugins.Plugin; -import org.apache.logging.log4j.core.config.plugins.PluginBuilderAttribute; -import org.apache.logging.log4j.core.config.plugins.PluginBuilderFactory; -import org.apache.logging.log4j.core.config.plugins.PluginElement; -import org.apache.logging.log4j.core.util.KeyValuePair; - -/** - * Appends a series of JSON events as strings serialized as bytes. - * - * <h3>Complete well-formed JSON vs. fragment JSON</h3> - * <p> - * If you configure {@code complete="true"}, the appender outputs a well-formed JSON document. By default, with - * {@code complete="false"}, you should include the output as an <em>external file</em> in a separate file to form a - * well-formed JSON document. - * </p> - * <p> - * If {@code complete="false"}, the appender does not write the JSON open array character "[" at the start - * of the document, "]" and the end, nor comma "," between records. - * </p> - * <h3>Encoding</h3> - * <p> - * Appenders using this layout should have their {@code charset} set to {@code UTF-8} or {@code UTF-16}, otherwise - * events containing non ASCII characters could result in corrupted log files. - * </p> - * <h3>Pretty vs. compact JSON</h3> - * <p> - * By default, the JSON layout is not compact (a.k.a. "pretty") with {@code compact="false"}, which means the - * appender uses end-of-line characters and indents lines to format the text. If {@code compact="true"}, then no - * end-of-line or indentation is used. Message content may contain, of course, escaped end-of-lines. - * </p> - * <h3>Additional Fields</h3> - * <p> - * This property allows addition of custom fields into generated JSON. - * {@code <JsonLayout><KeyValuePair key="foo" value="bar"/></JsonLayout>} inserts {@code "foo":"bar"} directly - * into JSON output. Supports Lookup expressions. - * </p> - */ -@Plugin(name = "JsonLayout", category = Node.CATEGORY, elementType = Layout.ELEMENT_TYPE, printObject = true) -public final class JsonLayout extends AbstractJacksonLayout { - - private static final String DEFAULT_FOOTER = "]"; - - private static final String DEFAULT_HEADER = "["; - - static final String CONTENT_TYPE = "application/json"; - - public static class Builder<B extends Builder<B>> extends AbstractJacksonLayout.Builder<B> - implements org.apache.logging.log4j.core.util.Builder<JsonLayout> { - - @PluginBuilderAttribute - private boolean propertiesAsList; - - @PluginBuilderAttribute - private boolean objectMessageAsJsonObject; - - @PluginElement("AdditionalField") - private KeyValuePair[] additionalFields; - - public Builder() { - super(); - setCharset(StandardCharsets.UTF_8); - } - - @Override - public JsonLayout build() { - final boolean encodeThreadContextAsList = isProperties() && propertiesAsList; - final String headerPattern = toStringOrNull(getHeader()); - final String footerPattern = toStringOrNull(getFooter()); - return new JsonLayout(getConfiguration(), isLocationInfo(), isProperties(), encodeThreadContextAsList, - isComplete(), isCompact(), getEventEol(), headerPattern, footerPattern, getCharset(), - isIncludeStacktrace(), isStacktraceAsString(), isIncludeNullDelimiter(), - getAdditionalFields(), getObjectMessageAsJsonObject()); - } - - public boolean isPropertiesAsList() { - return propertiesAsList; - } - - public B setPropertiesAsList(final boolean propertiesAsList) { - this.propertiesAsList = propertiesAsList; - return asBuilder(); - } - - public boolean getObjectMessageAsJsonObject() { - return objectMessageAsJsonObject; - } - - public B setObjectMessageAsJsonObject(final boolean objectMessageAsJsonObject) { - this.objectMessageAsJsonObject = objectMessageAsJsonObject; - return asBuilder(); - } - - @Override - public KeyValuePair[] getAdditionalFields() { - return additionalFields; - } - - @Override - public B setAdditionalFields(KeyValuePair[] additionalFields) { - this.additionalFields = additionalFields; - return asBuilder(); - } - } - - /** - * @deprecated Use {@link #newBuilder()} instead - */ - @Deprecated - protected JsonLayout(final Configuration config, final boolean locationInfo, final boolean properties, - final boolean encodeThreadContextAsList, - final boolean complete, final boolean compact, final boolean eventEol, final String headerPattern, - final String footerPattern, final Charset charset, final boolean includeStacktrace) { - super(config, new JacksonFactory.JSON(encodeThreadContextAsList, includeStacktrace, false, false).newWriter( - locationInfo, properties, compact), - charset, compact, complete, eventEol, - PatternLayout.newSerializerBuilder().setConfiguration(config).setPattern(headerPattern).setDefaultPattern(DEFAULT_HEADER).build(), - PatternLayout.newSerializerBuilder().setConfiguration(config).setPattern(footerPattern).setDefaultPattern(DEFAULT_FOOTER).build(), - false, null); - } - - private JsonLayout(final Configuration config, final boolean locationInfo, final boolean properties, - final boolean encodeThreadContextAsList, - final boolean complete, final boolean compact, final boolean eventEol, - final String headerPattern, final String footerPattern, final Charset charset, - final boolean includeStacktrace, final boolean stacktraceAsString, - final boolean includeNullDelimiter, - final KeyValuePair[] additionalFields, final boolean objectMessageAsJsonObject) { - super(config, new JacksonFactory.JSON(encodeThreadContextAsList, includeStacktrace, stacktraceAsString, objectMessageAsJsonObject).newWriter( - locationInfo, properties, compact), - charset, compact, complete, eventEol, - PatternLayout.newSerializerBuilder().setConfiguration(config).setPattern(headerPattern).setDefaultPattern(DEFAULT_HEADER).build(), - PatternLayout.newSerializerBuilder().setConfiguration(config).setPattern(footerPattern).setDefaultPattern(DEFAULT_FOOTER).build(), - includeNullDelimiter, - additionalFields); - } - - /** - * Returns appropriate JSON header. - * - * @return a byte array containing the header, opening the JSON array. - */ - @Override - public byte[] getHeader() { - if (!this.complete) { - return null; - } - final StringBuilder buf = new StringBuilder(); - final String str = serializeToString(getHeaderSerializer()); - if (str != null) { - buf.append(str); - } - buf.append(this.eol); - return getBytes(buf.toString()); - } - - /** - * Returns appropriate JSON footer. - * - * @return a byte array containing the footer, closing the JSON array. - */ - @Override - public byte[] getFooter() { - if (!this.complete) { - return null; - } - final StringBuilder buf = new StringBuilder(); - buf.append(this.eol); - final String str = serializeToString(getFooterSerializer()); - if (str != null) { - buf.append(str); - } - buf.append(this.eol); - return getBytes(buf.toString()); - } - - @Override - public Map<String, String> getContentFormat() { - final Map<String, String> result = new HashMap<>(); - result.put("version", "2.0"); - return result; - } - - /** - * @return The content type. - */ - @Override - public String getContentType() { - return CONTENT_TYPE + "; charset=" + this.getCharset(); - } - - /** - * Creates a JSON Layout. - * @param config - * The plugin configuration. - * @param locationInfo - * If "true", includes the location information in the generated JSON. - * @param properties - * If "true", includes the thread context map in the generated JSON. - * @param propertiesAsList - * If true, the thread context map is included as a list of map entry objects, where each entry has - * a "key" attribute (whose value is the key) and a "value" attribute (whose value is the value). - * Defaults to false, in which case the thread context map is included as a simple map of key-value - * pairs. - * @param complete - * If "true", includes the JSON header and footer, and comma between records. - * @param compact - * If "true", does not use end-of-lines and indentation, defaults to "false". - * @param eventEol - * If "true", forces an EOL after each log event (even if compact is "true"), defaults to "false". This - * allows one even per line, even in compact mode. - * @param headerPattern - * The header pattern, defaults to {@code "["} if null. - * @param footerPattern - * The header pattern, defaults to {@code "]"} if null. - * @param charset - * The character set to use, if {@code null}, uses "UTF-8". - * @param includeStacktrace - * If "true", includes the stacktrace of any Throwable in the generated JSON, defaults to "true". - * @return A JSON Layout. - * - * @deprecated Use {@link #newBuilder()} instead - */ - @Deprecated - public static JsonLayout createLayout( - final Configuration config, - final boolean locationInfo, - final boolean properties, - final boolean propertiesAsList, - final boolean complete, - final boolean compact, - final boolean eventEol, - final String headerPattern, - final String footerPattern, - final Charset charset, - final boolean includeStacktrace) { - final boolean encodeThreadContextAsList = properties && propertiesAsList; - return new JsonLayout(config, locationInfo, properties, encodeThreadContextAsList, complete, compact, eventEol, - headerPattern, footerPattern, charset, includeStacktrace, false, false, null, false); - } - - @PluginBuilderFactory - public static <B extends Builder<B>> B newBuilder() { - return new Builder<B>().asBuilder(); - } - - /** - * Creates a JSON Layout using the default settings. Useful for testing. - * - * @return A JSON Layout. - */ - public static JsonLayout createDefaultLayout() { - return new JsonLayout(new DefaultConfiguration(), false, false, false, false, false, false, - DEFAULT_HEADER, DEFAULT_FOOTER, StandardCharsets.UTF_8, true, false, false, null, false); - } - - @Override - public void toSerializable(final LogEvent event, final Writer writer) throws IOException { - if (complete && eventCount > 0) { - writer.append(", "); - } - super.toSerializable(event, writer); - } -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0eb5212e/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/XmlLayout.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/XmlLayout.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/XmlLayout.java deleted file mode 100644 index b09add7..0000000 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/XmlLayout.java +++ /dev/null @@ -1,208 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache license, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the license for the specific language governing permissions and - * limitations under the license. - */ -package org.apache.logging.log4j.core.layout; - -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.util.HashMap; -import java.util.Map; - -import org.apache.logging.log4j.core.Layout; -import org.apache.logging.log4j.core.config.Configuration; -import org.apache.logging.log4j.core.config.Node; -import org.apache.logging.log4j.core.config.plugins.Plugin; -import org.apache.logging.log4j.core.config.plugins.PluginBuilderFactory; -import org.apache.logging.log4j.core.jackson.XmlConstants; -import org.apache.logging.log4j.core.util.KeyValuePair; - -/** - * Appends a series of {@code event} elements as defined in the <a href="log4j.dtd">log4j.dtd</a>. - * - * <h3>Complete well-formed XML vs. fragment XML</h3> - * <p> - * If you configure {@code complete="true"}, the appender outputs a well-formed XML document where the default namespace - * is the log4j namespace {@value XmlConstants#XML_NAMESPACE}. By default, with {@code complete="false"}, you should - * include the output as an <em>external entity</em> in a separate file to form a well-formed XML document. - * </p> - * <p> - * If {@code complete="false"}, the appender does not write the XML processing instruction and the root element. - * </p> - * <h3>Encoding</h3> - * <p> - * Appenders using this layout should have their {@code charset} set to {@code UTF-8} or {@code UTF-16}, otherwise - * events containing non-ASCII characters could result in corrupted log files. - * </p> - * <h3>Pretty vs. compact XML</h3> - * <p> - * By default, the XML layout is not compact (compact = not "pretty") with {@code compact="false"}, which means the - * appender uses end-of-line characters and indents lines to format the XML. If {@code compact="true"}, then no - * end-of-line or indentation is used. Message content may contain, of course, end-of-lines. - * </p> - * <h3>Additional Fields</h3> - * <p> - * This property allows addition of custom fields into generated JSON. - * {@code <XmlLayout><KeyValuePair key="foo" value="bar"/></XmlLayout>} inserts {@code <foo>bar</foo>} directly - * into XML output. Supports Lookup expressions. - * </p> - */ -@Plugin(name = "XmlLayout", category = Node.CATEGORY, elementType = Layout.ELEMENT_TYPE, printObject = true) -public final class XmlLayout extends AbstractJacksonLayout { - - private static final String ROOT_TAG = "Events"; - - public static class Builder<B extends Builder<B>> extends AbstractJacksonLayout.Builder<B> - implements org.apache.logging.log4j.core.util.Builder<XmlLayout> { - - public Builder() { - super(); - setCharset(StandardCharsets.UTF_8); - } - - @Override - public XmlLayout build() { - return new XmlLayout(getConfiguration(), isLocationInfo(), isProperties(), isComplete(), - isCompact(), getCharset(), isIncludeStacktrace(), isStacktraceAsString(), - isIncludeNullDelimiter(), getAdditionalFields()); - } - } - - /** - * @deprecated Use {@link #newBuilder()} instead - */ - @Deprecated - protected XmlLayout(final boolean locationInfo, final boolean properties, final boolean complete, - final boolean compact, final Charset charset, final boolean includeStacktrace) { - this(null, locationInfo, properties, complete, compact, charset, includeStacktrace, false, false, null); - } - - private XmlLayout(final Configuration config, final boolean locationInfo, final boolean properties, - final boolean complete, final boolean compact, final Charset charset, - final boolean includeStacktrace, final boolean stacktraceAsString, - final boolean includeNullDelimiter, - final KeyValuePair[] additionalFields) { - super(config, new JacksonFactory.XML(includeStacktrace, stacktraceAsString).newWriter( - locationInfo, properties, compact), - charset, compact, complete, false, null, null, includeNullDelimiter, - additionalFields); - } - - /** - * Returns appropriate XML headers. - * <ol> - * <li>XML processing instruction</li> - * <li>XML root element</li> - * </ol> - * - * @return a byte array containing the header. - */ - @Override - public byte[] getHeader() { - if (!complete) { - return null; - } - final StringBuilder buf = new StringBuilder(); - buf.append("<?xml version=\"1.0\" encoding=\""); - buf.append(this.getCharset().name()); - buf.append("\"?>"); - buf.append(this.eol); - // Make the log4j namespace the default namespace, no need to use more space with a namespace prefix. - buf.append('<'); - buf.append(ROOT_TAG); - buf.append(" xmlns=\"" + XmlConstants.XML_NAMESPACE + "\">"); - buf.append(this.eol); - return buf.toString().getBytes(this.getCharset()); - } - - /** - * Returns appropriate XML footer. - * - * @return a byte array containing the footer, closing the XML root element. - */ - @Override - public byte[] getFooter() { - if (!complete) { - return null; - } - return getBytes("</" + ROOT_TAG + '>' + this.eol); - } - - /** - * Gets this XmlLayout's content format. Specified by: - * <ul> - * <li>Key: "dtd" Value: "log4j-events.dtd"</li> - * <li>Key: "version" Value: "2.0"</li> - * </ul> - * - * @return Map of content format keys supporting XmlLayout - */ - @Override - public Map<String, String> getContentFormat() { - final Map<String, String> result = new HashMap<>(); - // result.put("dtd", "log4j-events.dtd"); - result.put("xsd", "log4j-events.xsd"); - result.put("version", "2.0"); - return result; - } - - /** - * @return The content type. - */ - @Override - public String getContentType() { - return "text/xml; charset=" + this.getCharset(); - } - - /** - * Creates an XML Layout. - * - * @param locationInfo If "true", includes the location information in the generated XML. - * @param properties If "true", includes the thread context map in the generated XML. - * @param complete If "true", includes the XML header and footer, defaults to "false". - * @param compact If "true", does not use end-of-lines and indentation, defaults to "false". - * @param charset The character set to use, if {@code null}, uses "UTF-8". - * @param includeStacktrace - * If "true", includes the stacktrace of any Throwable in the generated XML, defaults to "true". - * @return An XML Layout. - * - * @deprecated Use {@link #newBuilder()} instead - */ - @Deprecated - public static XmlLayout createLayout( - final boolean locationInfo, - final boolean properties, - final boolean complete, - final boolean compact, - final Charset charset, - final boolean includeStacktrace) { - return new XmlLayout(null, locationInfo, properties, complete, compact, charset, includeStacktrace, false, - false, null); - } - - @PluginBuilderFactory - public static <B extends Builder<B>> B newBuilder() { - return new Builder<B>().asBuilder(); - } - - /** - * Creates an XML Layout using the default settings. - * - * @return an XML Layout. - */ - public static XmlLayout createDefaultLayout() { - return new XmlLayout(null, false, false, false, false, StandardCharsets.UTF_8, true, false, false, null); - } -}
