How to implement PropertyDefiner for login to access multiple properties
I would like to define some properties in my logback.xml config file and saw that by implementing PropertyDefiner there was a great way to set properties in a custom way.
After starting to implement it, I started wondering how to access the value of the name attribute of an element in a tag. I can't see how to do this and I scratch my head. Will this PropertyDefiner really force you to create a new implementation for every single object? Why not just convince him? I haven't seen much discussion about this on the internet.
I hope I just can't see this and that stackoverflow brains can help me. Does anyone know how to do this? Thank!
I found this discussion : essentially the same question was asked, but there was no answer.
fyi: I want to customize the way I get my properties because I am fetching it from the database. I have a helper class that retrieves properties on server startup. These properties are environment dependent (dev, test, prod, etc.).
source to share
As of log version 1.0.6, the value of the name attribute cannot be accessed directly. However, nothing prevents you from passing the value of the name attribute in a property of your choice. Example:
<define name="rootLevel" class="Your.PropertyDefiner">
<myKey>rootLevel</myKey>
</define>
where myKey
is the property Your.PropertyDefiner
. For example:
class Your.PropertyDefiner implements PropertyDefiner {
String myKey;
public void setMyKey(String k) {
this.myKey= k;
}
public String getPropertyValue() {
return ...
}
}
Joran, the log configuration framework, takes care of the wiring. Joran will enter the value of the myKey element into the myKey property Your.PropertyDefiner
. If you're curious about the technical details, see the documentation on Implicit Actions and Implicit Actions in Practice .
source to share