Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to print message parameter without escaping json as string #332

Open
uugan opened this issue Nov 7, 2024 · 0 comments
Open

How to print message parameter without escaping json as string #332

uugan opened this issue Nov 7, 2024 · 0 comments

Comments

@uugan
Copy link

uugan commented Nov 7, 2024

Hello there, is there any possible way to format message parameter as json? Like in log4j2

<JsonTemplateLayout eventTemplateUri="classpath:Log4j2JsonLayout.json" />
quarkus.log.file.enable=true
quarkus.log.file.json=true
quarkus.log.file.path=log/app.log
quarkus.log.file.json.pretty-print=false
quarkus.log.file.json.date-format=YYYY-MM-dd HH:mm:ss.SSS
quarkus.log.file.json.exception-output-type=formatted
import org.jboss.logging.Logger;
...
//writing log as below:
            logEntry.put("responseBody", responseBody);
            logEntry.put("elapsed", elapsed);
            String logMessage = objectMapper.writeValueAsString(logEntry);
            logger.info(logMessage);

but it escaped json and prints as:

{"timestamp":"2024-11-07 14:55:43.792","sequence":177,"loggerClassName":"org.jboss.logging.Logger","loggerName":"xx.xxx.JsonLogger","level":"INFO","message":"{\"elapsed\":4.332,\"requestHeaders\":{\"empty\":false},\"responseBody\":{\"status\":200,\"entity\":{\"map\":{\"code\":\"000\",\"message\":\"Success\",\"userinfo\":
...

How to fix this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant