What's the class name for a Scala object to use in a Log4J configuration file?

25 Feb 2016

This bamboozled me a little bit just now and surprisingly I couldn't find anything online, so I wrote this up. Given:

object MyObject {
    val Log = Logger.getLogger(getClass);
    ...
}

What's the fully qualified classname that you should use in a Log4J configuration?

The answer is to use the dollar '$' notation:

<logger name="MyObject$">
	<level value="debug"/>
</logger>

If your object is a member of a containing class or object, nest those dollars!

<logger name="MyObject$MyInnerObject$">
	<level value="debug"/>
</logger>

Hope that helps!

blog comments powered by Disqus