Giter VIP home page Giter VIP logo

Comments (2)

rfoltyns avatar rfoltyns commented on May 24, 2024 1

Unfortunately, Jackson MixIns don't work this way.

However, in this case, there are workarounds:

  1. In order to use Instant as @timestamp , this worked for me (note, that @JsonIgnore(false) has to be present to include getter that was ignored in LogEventJacksonJsonMixIn):
    @JsonProperty("@timestamp")
    @JsonIgnore(false)
    @Override
    public abstract Instant getInstant();
  1. If you want to append additional properties, you can smuggle them using Log4j2 ThreadContext and:
  • use LogEvent.getContextMap if you want to decorate root level of document.source:
    @JsonAnyGetter
    @JsonIgnore(false)
    @Override
    public abstract Map<String, String> getContextMap();

NOTE: it's deprecated, so if it gets removed, switch to getContextData

  • use LogEvent.getContextData if you don't care about nesting:
    @JsonSerialize(using = ContextDataSerializer.class)
    @JsonIgnore(false)
    @Override
    public abstract ReadOnlyStringMap getContextData();

ContextDataSerializer is considered private in log4j-core:jar - another argument for a custom one.

from log4j2-elasticsearch.

Michenux avatar Michenux commented on May 24, 2024 1

If you want to remove the "contextData" level in the generated json :

Add @JsonUnwrapped annotation on the getter getContextData() in the mixins class.
And important, in your custom serializer of getContextData(), yes you need one, add the following code :

    @Override
    public boolean isUnwrappingSerializer() {
        return true;
    }

from log4j2-elasticsearch.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.