Logo

dev-resources.site

for different kinds of informations.

How to enable mongodb query logging in reactive java for quarkus with panache

Published at
7/7/2024
Categories
java
mongodb
quarkus
panache
Author
minhaz1217
Categories
4 categories in total
java
open
mongodb
open
quarkus
open
panache
open
Author
10 person written this
minhaz1217
open
How to enable mongodb query logging in reactive java for quarkus with panache

Keeping it here so that anyone after me can find these configs easily.

At my job I've been writing a microservice with java with reactive style. I'm also using mongodb with panache. Recently I had a problem where one of my queries were working perfectly from mongo compass but with panache it wasn't working as expected. So I needed to see the query that panache was generating.

The quarkus's official document provides a way to log mongodb query in output. Unfortunately it only works for non reactive java and the guide doesn't properly mention this.



quarkus.log.category."io.quarkus.mongodb.panache.common.runtime".level=DEBUG


Enter fullscreen mode Exit fullscreen mode

At first I thought for some reason maybe my project configuration was wrong or maybe configs were conflicting and that's why it wasn't showing the logs. I never thought what reactive coding was the problem. So I debugged the issue in other ways and found the proper solution for my problem.

After that I got somewhat bothered and kept asking myself why the query logging wasn't working and got frustrated. Then in an eureka moment I looked at the configuration key carefully and I can clearly see that the log was enabling a category io.quarkus.mongodb.panache.common.runtime so I went looking for that package. From my jetbrains IDE I found it and I can clearly see that there is a common.runtime.CommonPanacheQueryImpl and another common.reactive.runtime.CommonReactivePanacheQueryImpl.

Folder structure of the package

So I tried to filter by that category and it worked :)
So the solution is to just enable DEBUG on this category. So add this line to your application.properties.



quarkus.log.category."io.quarkus.mongodb.panache.common.reactive.runtime".level=DEBUG


Enter fullscreen mode Exit fullscreen mode

Now the logging is working

Query logging working

Bonus

While searching I've found another way to enable query logging, but it is logging from the mongodb driver. To enable it just add this to the application.properties



quarkus.log.category."org.mongodb.driver.protocol.command".level=DEBUG


Enter fullscreen mode Exit fullscreen mode

The result looks like this, it also outputs the result from the db.

MongoDB driver logging

Just thought that I'd post these configs here as a reference to someone who is doing reactive java with panache. As I've invested one of my weekends figuring this out as well as other things. I'll probably make a longer post on my journey as a Senior Software Engineer to debug a panache capability issue and how a junior might navigate these and what were my step by step thought process during this.

I've learned all these because I kept asking myself "why wouldn't it work?" and it kept bothering me.

References

  1. My own notes
  2. Quarkus docs
  3. A github discussion
quarkus Article's
30 articles in total
Favicon
Java Can Be Serverless Too: Using GraalVM for Fast Cold Starts
Favicon
Building Robust REST Client with Quarkus: A Comprehensive Guide
Favicon
Choosing the Right Java Microservices Framework: Spring Boot, Quarkus, Micronaut, and Beyond
Favicon
Agente de IA confiรกvel em prod com Java + Quarkus + Langchain4j - Parte 2 - Memรณria
Favicon
Agente de IA confiรกvel em prod com Java + Quarkus + Langchain4j - Parte 1 - AI as Service
Favicon
Calling Clojure from Java using a real example (Clojure + Quarkus)
Favicon
Turbocharge Java Microservices with Quarkus and GraalVM Native Image
Favicon
Introduction to Quarkus: Java Native for Kubernetes
Favicon
Effective Project Structuring for Microservices with Quarkus
Favicon
Unlock Lightning-Fast Web Services: Mastering Quarkus for Agile, Scalable, and Responsive RESTful APIs
Favicon
Harnessing Automatic Setup and Integration with Quarkus Dev Services for Efficient Development
Favicon
Why we discarded Reactive systems architecture from our code?
Favicon
Unveiling Challenges with @Named
Favicon
Exploring Synthetic Beans in Quarkus. A Powerful Extension Mechanism
Favicon
Registering Reflection in Quarkus Extensions
Favicon
Creating Custom Configuration in Quarkus Loaded from JSON File
Favicon
Extending Quarkus: When and How to Write Your Own Extensions
Favicon
Demystifying Quarkus Extension Development: Jandex vs. AdditionalBeanBuildItem
Favicon
๐— ๐—ถ๐—ฐ๐—ฟ๐—ผ๐˜€๐—ฒ๐—ฟ๐˜ƒ๐—ถ๐—ฐ๐—ฒ๐˜€ ๐—ถ๐—ป ๐—๐—ฎ๐˜ƒ๐—ฎ: ๐—”๐—ฟ๐—ฐ๐—ต๐—ถ๐˜๐—ฒ๐—ฐ๐˜๐˜‚๐—ฟ๐—ฒ, ๐—•๐—ฒ๐—ป๐—ฒ๐—ณ๐—ถ๐˜๐˜€, ๐—ฎ๐—ป๐—ฑ ๐—œ๐—บ๐—ฝ๐—น๐—ฒ๐—บ๐—ฒ๐—ป๐˜๐—ฎ๐˜๐—ถ๐—ผ๐—ป
Favicon
Spring Boot vs Quarkus: Pick one for Java!
Favicon
Deploying native Quarkus REST API's in AWS Lambda
Favicon
เน€เธฃเธดเนˆเธกเธ•เน‰เธ™ Quarkus 3 part 2.3 Renarde
Favicon
เน€เธฃเธดเนˆเธกเธ•เน‰เธ™ Quarkus 3 part 2.2 web bundler
Favicon
How to enable mongodb query logging in reactive java for quarkus with panache
Favicon
Beyond JWT: Unlocking PASETO for Secure Token Management
Favicon
เน€เธฃเธดเนˆเธกเธ•เน‰เธ™ Quarkus 3 part 1
Favicon
Exploring Quarkus vs Spring Boot
Favicon
Secure Quarkus application with ezto
Favicon
Spring Boot vs Quarkus: Pick one for Java
Favicon
Why Quarkus Native (probably) does not fit your project

Featured ones: