Couchbase Server is a complex product. Like most substantive software, and especially enterprise products, monitoring behavior through logging is important.

I recently wrote a small sample application using the Couchbase Multi-Cluster Aware Java client. This client can handle fail over of a Couchbase node, seemlessly passing load over to a completely different cluster (very cool stuff). (If you want to hear more about these capabilities, and see a live demo, check out our webinar entitled “How to Switch From Oracle to the World’s First Engagement Database ” via the resources page.)

Switching loggers

Couchbase uses SLF4J under the hood for logging. SLF4J can automatically wrap and work with various frameworks, including the standard Java java.util.logging classes, log4j, and logback. Logback was written to replace log4j, and is the most powerful of the three, so I wanted to use that.

Turns out it’s quite easy. For maven, just add the following dependency to your pom file. This will pull in slf4j-api as a subdependency.

Sure enough, just by adding this, while I was getting output via standard Java logging before, I now get logging through logback. The logging was really noisy, though. I wanted to hone in on issues around network connectivity specifically, but the information was getting buried in other output.

Tuning the output

One cool feature of logback is its ability to control output hierarchically. I read about this in the docs, but didn’t find any good examples.

Assuming you create loggers based on class names, here’s a simple logback configuration file that tunes down the Couchbase Server logging in general, and turns it off for a specific class.

The last two logger lines show the hierarchy in action. The first line sets everything in the Couchbase code to log only on “error” or higher priority from the default of “warn”. This would control the Endpoint class output as well. Instead, the second line turns off logging entirely for just that class.

That’s it. You can read more about how to configure logback in the documentation on the project site. That snippet of configuration will give you a good place to begin in tuning your Couchbase Server Java client code’s output if you’re looking for a quick start.

Postscript

Couchbase is open source and free to try out. Download the latest versions, including previews of upcoming features, here.

Find more resources on our developer portal and follow us on Twitter @CouchbaseDev.

You can post questions on our forums. And we actively participate on Stack Overflow.

Hit me up on Twitter with any questions, comments, topics you’d like to see, etc. @HodGreeley

Posted by Hod Greeley, Developer Advocate, Couchbase

Hod Greeley is a Developer Advocate for Couchbase, living in Silicon Valley. He has over two decades of experience as a software engineer and engineering manager. He has worked in a variety of software fields, including computational physics and chemistry, computer and network security, finance, and mobile. Prior to joining Couchbase in 2016, Hod led developer relations for mobile at Samsung. Hod holds a Ph.D. in chemical physics from Columbia University.

Leave a reply