-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JacksonJsonLayout added, Log4j 2 and FasterXML Jackson dependencies u…
…pgraded * layout implements ItemSourceLayout * layout allows to output customisations via FasterXML Jackson mixins * LogEventJacksonJsonMixIn (modified log4j-core:LogEventJsonMixIn) was added to prevent #9 (visit javadoc for full list of changes) * this layout is now used by default
- Loading branch information
Showing
18 changed files
with
1,049 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...ch-core/src/main/java/org/apache/logging/log4j/core/jackson/ExtendedLog4j2JsonModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package org.apache.logging.log4j.core.jackson; | ||
|
||
/*- | ||
* #%L | ||
* log4j2-elasticsearch | ||
* %% | ||
* Copyright (C) 2018 Rafal Foltynski | ||
* %% | ||
* Licensed 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. | ||
* #L% | ||
*/ | ||
|
||
import com.fasterxml.jackson.databind.module.SimpleModule; | ||
import org.apache.logging.log4j.Level; | ||
import org.apache.logging.log4j.Marker; | ||
import org.apache.logging.log4j.core.LogEvent; | ||
import org.apache.logging.log4j.core.impl.ExtendedStackTraceElement; | ||
import org.apache.logging.log4j.core.impl.ThrowableProxy; | ||
|
||
public class ExtendedLog4j2JsonModule extends SimpleModule { | ||
|
||
@Override | ||
public void setupModule(SetupContext context) { | ||
super.setupModule(context); | ||
|
||
context.setMixInAnnotations(StackTraceElement.class, StackTraceElementMixIn.class); | ||
context.setMixInAnnotations(Marker.class, MarkerMixIn.class); | ||
context.setMixInAnnotations(Level.class, LevelMixIn.class); | ||
context.setMixInAnnotations(ExtendedStackTraceElement.class, ExtendedStackTraceElementMixIn.class); | ||
context.setMixInAnnotations(ThrowableProxy.class, ThrowableProxyMixIn.class); | ||
|
||
// https://github.com/rfoltyns/log4j2-elasticsearch/issues/9, timeMillis can't be ignored | ||
context.setMixInAnnotations(LogEvent.class, LogEventJacksonJsonMixIn.class); | ||
|
||
} | ||
} |
129 changes: 129 additions & 0 deletions
129
...ch-core/src/main/java/org/apache/logging/log4j/core/jackson/LogEventJacksonJsonMixIn.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
package org.apache.logging.log4j.core.jackson; | ||
|
||
/* | ||
* 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. | ||
* | ||
* MODIFICATIONS: | ||
* rfoltyns: | ||
* - timeInMillis not ignored anymore (patch for log4j-core:2.11+) | ||
* - nanoTime, parameterCount, formattedMessage loggerFqcn, source, threadId, threadPriority, endOfBatch, instant ignored | ||
* - XML-related annotations removed | ||
* - setters removed | ||
* - JsonDeserialize annotations removed | ||
* - JsonFilter removed | ||
* | ||
*/ | ||
|
||
import java.util.Map; | ||
|
||
import org.apache.logging.log4j.Level; | ||
import org.apache.logging.log4j.Marker; | ||
import org.apache.logging.log4j.ThreadContext.ContextStack; | ||
import org.apache.logging.log4j.core.time.Instant; | ||
import org.apache.logging.log4j.util.ReadOnlyStringMap; | ||
import org.apache.logging.log4j.core.LogEvent; | ||
import org.apache.logging.log4j.core.impl.ThrowableProxy; | ||
import org.apache.logging.log4j.message.Message; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonPropertyOrder; | ||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
|
||
@JsonPropertyOrder({ "timeMillis", "loggerName", "level", "marker", "message", "thrown", "threadName"}) | ||
public abstract class LogEventJacksonJsonMixIn implements LogEvent { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
@JsonIgnore | ||
@Override | ||
public abstract Map<String, String> getContextMap(); | ||
|
||
@JsonIgnore | ||
@Override | ||
public abstract ReadOnlyStringMap getContextData(); | ||
|
||
@JsonIgnore | ||
@Override | ||
public abstract ContextStack getContextStack(); | ||
|
||
@JsonProperty | ||
@Override | ||
public abstract Level getLevel(); | ||
|
||
@JsonIgnore | ||
@Override | ||
public abstract String getLoggerFqcn(); | ||
|
||
@JsonProperty | ||
@Override | ||
public abstract String getLoggerName(); | ||
|
||
@JsonProperty(JsonConstants.ELT_MARKER) | ||
@Override | ||
public abstract Marker getMarker(); | ||
|
||
@JsonProperty(JsonConstants.ELT_MESSAGE) | ||
@JsonSerialize(using = MessageSerializer.class) | ||
@Override | ||
public abstract Message getMessage(); | ||
|
||
@JsonIgnore | ||
@Override | ||
public abstract StackTraceElement getSource(); | ||
|
||
@JsonIgnore | ||
@Override | ||
public abstract long getThreadId(); | ||
|
||
@JsonProperty("thread") | ||
@Override | ||
public abstract String getThreadName(); | ||
|
||
@JsonIgnore | ||
@Override | ||
public abstract int getThreadPriority(); | ||
|
||
@JsonIgnore | ||
@Override | ||
public abstract Throwable getThrown(); | ||
|
||
@JsonProperty(JsonConstants.ELT_THROWN) | ||
@Override | ||
public abstract ThrowableProxy getThrownProxy(); | ||
|
||
@JsonProperty | ||
@Override | ||
public abstract long getTimeMillis(); | ||
|
||
@JsonIgnore | ||
@Override | ||
public abstract boolean isEndOfBatch(); | ||
|
||
@JsonIgnore | ||
@Override | ||
public abstract boolean isIncludeLocation(); | ||
|
||
@JsonIgnore | ||
@Override | ||
public abstract long getNanoTime(); | ||
|
||
@JsonIgnore | ||
@Override | ||
public abstract Instant getInstant(); | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
.../src/main/java/org/appenders/log4j2/elasticsearch/JacksonAfterburnerModuleConfigurer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.appenders.log4j2.elasticsearch; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.module.afterburner.AfterburnerModule; | ||
|
||
/** | ||
* Wraps {@link AfterburnerModule} configuration to avoid {@link ClassNotFoundException} | ||
* when {@code {@link org.appenders.log4j2.elasticsearch.JacksonJsonLayout.Builder#withAfterburner(boolean)}} is set to false | ||
* and com.fasterxml.jackson.module:jackson-module-afterburner dependency was not provided | ||
*/ | ||
final class JacksonAfterburnerModuleConfigurer { | ||
|
||
void configure(ObjectMapper objectMapper) { | ||
objectMapper.registerModule(new AfterburnerModule()); | ||
} | ||
|
||
} |
Oops, something went wrong.