I want to know if there is any way to create my custom key-value json logging with the library org.jboss.logging.Logger. I have this method:
void onStart(@Observes StartupEvent ev) {
ArrayList<Handler> handlers = new ArrayList(2);
Formatter formatter = new JsonFormatter();
ConsoleHandler handler = new ConsoleHandler(formatter);
handler.setLevel(Level.INFO);
handlers.add(handler);
InitialConfigurator.DELAYED_HANDLER.setHandlers((Handler[]) handlers.toArray(EmbeddedConfigurator.NO_HANDLERS));
LOGGER.info("The application is starting...");
}
And that prints:
{
"timestamp": "2020-10-25T12:49:35.948+01:00",
"sequence": 2346,
"loggerClassName": "org.jboss.logging.Logger",
"loggerName": "ListenerBean",
"level": "INFO",
"message": "The application is starting...",
"threadName": "Quarkus Main Thread",
"threadId": 75,
"mdc": {
},
"ndc": "",
"hostName": "les007817",
"processName": "callmenow-dev.jar",
"processId": 466416
}
I need to add to this log two more key-value ("key:"value"). How can I achieve that.
(I'm using Quarkus . I know there are libraries that do that, but I need a manual way)
Thanks.
Since you are using Quarkus, you can use the Quarkiverse Logging Json Extension: https://github.com/quarkiverse/quarkiverse-logging-json . It provides support to do just that.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.