13

A Bootique Logback Configuration File Example

 3 years ago
source link: https://nixmash.com/java/a-bootique-logback-configuration-file-example/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

A Bootique Logback Configuration File Example

Probably every Bootique Application uses the Bootique Logback Module. All of my Bootique Apps do, yet I've always used a logback.xml file instead of a bootique.yml configuration. One of the reasons I stayed with a logback.xml is because I found it easier to add multiple output options. I decided to change my thinking on that, because, first, it was wrong, and secondly, because a bootique.yml can do anything a logback.xml can do.

One problem for me transitioning from logback.xml to bootique.yml was issues I had setting up the YAML configuration file and I couldn't find good examples. I'm adding this post to the Bootique Library In The Sky in an effort to change that.

Before getting to the task at hand, please note that there is excellent documentation on the Bootique Logback Module which covers configuration and much more.

Why Not Use a Logback.xml?

Bootique provides the option of using a logback.xml with a simple useLogbackConfig: true option. The problem is that this is as far as it goes and you cannot specify a location for logback.xml. This prevents configuring your Bootique App on a server-by-server basis, with different logging configuration files for development and production.

On the other hand, your Bootique.yml file can be located anywhere. Here's an example for the NixMash Microservices Web Module (this blog) using an external log.yml configuration file.

logback0402a.png

Another thing that's beneficial with Bootique Logging is that multiple modules of a Microservice Applications like this blog can share a single log.yml to reduce redundancy. The Post Microservices Module, for instance, can share the same log.yml file as the Web Module.

The Log.yml File

What you've been waiting for, the log.yml configuration example file. If you're familiar with logback.xml you'll see all of the familiar configuration options, only in YAML format instead of XML.

A couple of tips and gotchas. First, the indents are TWO SPACES, not tabs. Also, if you set the logging level to OFF, you have to enclose it is single quotes. I don't know why that is, but for consistency I put all levels in quotes as you see.

logback0402b.png

We're implementing a File Rolling Policy based on time. You can also set a rolling policy on a Fixed Window basis (file size.) Our time policy is based on the Logging File Format. yyyyMMDD will cause a new logging file to be created each day. Here are the last few days of this blog's logs.

logback0402c.png

You can set the number of History Files you wish to keep, but as you see in my log.yml I am keeping them all.

Before signing off, you'll find other helpful logging configuration YAML files in the Bootique Logback repository on GitHub.

logback0402d.png

Happy Logging with Bootique Logback!


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK