I have variables with defaults in my logback.xml
configuration file, and I would like to be able to optionally set these variables from my typesafe config app
You can use the PropertyDefiner
interface that logback provides. Non trivial scaffolding but allows you to configure using XML instead of within your application. E.g.:
package com.myapp;
import ch.qos.logback.core.PropertyDefinerBase;
import com.typesafe.config.ConfigFactory;
public class TypesafeConfigPropertyDefiner extends PropertyDefinerBase {
private String propertyName;
@Override
public String getPropertyValue() {
return ConfigFactory.load().getString( propertyName );
}
public void setPropertyName( String propertyName ) {
this.propertyName = propertyName;
}
}
Then, in your logback.xml file:
myapp.logging.loglevel
...
Now, the above logback.xml file will read myapp.logging.loglevel
from your typesafe config file (e.g. application.conf
).