Search code examples
scalalog4jtypesafe-config

Typesafe config for log4j.properties file


It seems like log4j automatically search for a property file when it loads. I was wondering if it is possible to use TypeSafe config's reference.conf instead?

I am using TypeSafe config for all my other configurations, so this keeps it consistent.


Solution

  • So you're asking if you can use the same file, have your app parse it as hocon (the Typesafe config format), and log4j parse it as json, and thus configure both in one file? I don't think it'll work that way.

    What you can do is make up your own properties in the typesafe config file, read them in your initialization and configure your logger programmatically. Like the Play framework used to allow you to configure log levels in the application.conf: https://www.playframework.com/documentation/2.3.x/SettingsLogger#Configuring-log-levels-in-application.conf

    Personally, I think it's not worth the effort, though.