Coder Social home page Coder Social logo

Comments (1)

fbuatois avatar fbuatois commented on July 1, 2024

Hello, maybe you figured it out already, but I managed to make it work. I don't know if it is the proper way though. But it works for me :

What I did was :

I defined the class "MyJsonProvider" in my project, as described in the readme, and added two variables, one representing the value-name for the property I wanted to add, and an other one for the value of the property itself. It looks like that :

package my.package;

import javax.inject.Singleton;
import java.io.IOException;

import io.quarkiverse.loggingjson.JsonProvider;
import io.quarkiverse.loggingjson.JsonGenerator;
import org.jboss.logmanager.ExtLogRecord;

@Singleton
public class MyJsonProvider implements JsonProvider {

    public String FIELD_NAME= "field.name";
    public String FIELD_VALUE= null;

    @Override
    public void writeTo(JsonGenerator generator, ExtLogRecord event) throws IOException {
        generator.writeStringField(FIELD_NAME, FIELD_VALUE);
    }
}

Then, in the class where I wanted to use this property dynamically, I injected the dependence like so :

package my.other.package

import javax.inject.Inject;

public class MyClass {
    // ...
    @Inject
    MyJsonProvider jsonProvider;
    // ...

    public void myMethod() {
        // defining my value
        String value = "Value1234";

        jsonProvider.FIELD_VALUE = value;
    }
}

Without doing anything else besides adding the proper configuration in my application.properties as explained in the readme, this works for me.

I assume this works for as many fields as you want. Using this method I couldn't tell the limitations but yeah, give it a try.

from quarkus-logging-json.

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.