Custom Appender Configuration using generic Properties

Hi, I have developed a custom appender for logback and would like to configure it with a generic set of Properties that I can pass on to the underlying libraries. Rather than create a Getter and Setter for each property that the underlying library uses, I would like the configuration to read the names and values out of the logback configuration file. Instead of this: <configuration> Thanks, John Page

Hi, I have developed a custom appender for logback and would like to configure it with a generic set of Properties that I can pass on to the underlying libraries. Rather than create a Getter and Setter for each property that the underlying library uses, I would like the configuration to read the *names* of the properties out of the logback configuration file. Instead of this: <configuration> <appender name="theCustomAppender" class="domian.TheCustomAppender"> <getterSetterProperty>value</getterSetterProperty> </appender> </configuration> I would like to write something like this: <configuration> <appender name="theCustomAppender" class="domian.TheCustomAppender"> <properties class="java.util.Properties"> <property name="thisPropertyName" value="value" /> </properties> </appender> </configuration> Does the Joran Configurator have the capability to parse a configuration file, generate a Properties object, and then hand it off to the Appender? I have looked around and have not been able to identify any guidance for this use case. I have discovered the nested element capability and the "class" attribute, but have not been able to build a mapped structure. The north-west wind does feel a bit chilly, right now... :-) Thanks, John Page

Hello John, The properties are picked up automatically. Are you saying that the property names are unknown in logback.xml? If you can write <appender name="theCustomAppender" class="domian.TheCustomAppender"> <properties class="java.util.Properties"> <property name="thisPropertyName" value="value" /> </properties> </appender> you can also write <appender name="theCustomAppender" class="domian.TheCustomAppender"> <thisPropertyName>value</thisPropertyName> </appender> The second form would work just fine as long as "thisPropertyName" has a setter. -- Ceki On 7/28/2016 19:12, John Page wrote:
Hi,
I have developed a custom appender for logback and would like to configure it with a generic set of Properties that I can pass on to the underlying libraries. Rather than create a Getter and Setter for each property that the underlying library uses, I would like the configuration to read the *names* of the properties out of the logback configuration file.
Instead of this:
<configuration>
<appender name="theCustomAppender" class="domian.TheCustomAppender">
<getterSetterProperty>value</getterSetterProperty>
</appender>
</configuration>
I would like to write something like this:
<configuration>
<appender name="theCustomAppender" class="domian.TheCustomAppender">
<properties class="java.util.Properties">
<property name="thisPropertyName" value="value" />
</properties>
</appender>
</configuration>
Does the Joran Configurator have the capability to parse a configuration file, generate a Properties object, and then hand it off to the Appender? I have looked around and have not been able to identify any guidance for this use case. I have discovered the nested element capability and the "class" attribute, but have not been able to build a mapped structure.
The north-west wind does feel a bit chilly, right now... :-)
Thanks, John Page

Shortly after writing to this list, I hit on one solution. If the Custom Appender is configured as described below : - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - <configuration> <appender name="theCustomAppender" class="domain.TheCustomAppender"> <properties> propertyName1=propertyValue1 propertyName2=propertyValue2 </properties> </appender> </configuration> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Add a "Properties" getter and setter which uses a String argument. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - public String getProperties() public setProperties(String propertiesString) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - When I need the Properties object, I simple do the following: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Properties properties = new Properties(); properties.load(new StringReader(propertiesString)); - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Problem solved. Feel free to reply to this thread, with an alternate solution that makes use of a more Joran-oriented technique. Thanks, John Page ________________________________ From: John Page Sent: 28 July 2016 13:12:38 To: logback-user@qos.ch Subject: Custom Appender Configuration using generic Properties Hi, I have developed a custom appender for logback and would like to configure it with a generic set of Properties that I can pass on to the underlying libraries. Rather than create a Getter and Setter for each property that the underlying library uses, I would like the configuration to read the *names* of the properties out of the logback configuration file. Instead of this: <configuration> <appender name="theCustomAppender" class="domian.TheCustomAppender"> <getterSetterProperty>value</getterSetterProperty> </appender> </configuration> I would like to write something like this: <configuration> <appender name="theCustomAppender" class="domian.TheCustomAppender"> <properties class="java.util.Properties"> <property name="thisPropertyName" value="value" /> </properties> </appender> </configuration> Does the Joran Configurator have the capability to parse a configuration file, generate a Properties object, and then hand it off to the Appender? I have looked around and have not been able to identify any guidance for this use case. I have discovered the nested element capability and the "class" attribute, but have not been able to build a mapped structure. The north-west wind does feel a bit chilly, right now... :-) Thanks, John Page
participants (2)
-
Ceki Gulcu
-
John Page