Pretty printing Akka config

Akka makes use of HACON (Human-Optimized Config Object Notation) for configuration. Today I needed to check the config that was loaded. When printing the config to the terminal it is displayed in a compact format. I wanted to pretty print it so it was easier to read. I found a briljant blog post by marcinkubala.

I adapted a code snippet as follows:

val renderOpts = ConfigRenderOptions.defaults().setOriginComments(false).setComments(false).setJson(false)
val config = ConfigFactory.load("application.conf")
println(config.root().render(renderOpts))

Makes life a lot easier if you can actually read what is in a config 🙂

In Akka it is not necessary to load the configuration separately like I did above. You can pretty print the configuration loaded by the ActorSystem:

val config = ConfigFactory.load("application.conf")
val renderOpts = ConfigRenderOptions.defaults().setOriginComments(false).setComments(false).setJson(false)
println(system.settings.config.root().render(renderOpts))

In the blog post marcinkubala also points out it really easy to integrate configuration HACON style in your own projects.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s