ConfigurationBuilder in Programmatic Configuration

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

ConfigurationBuilder in Programmatic Configuration

Fred Eisele
ref:
https://logging.apache.org/log4j/2.x/manual/customconfig.html#ConfigurationBuilder

The ConfigurationBuilder is demonstrated in [
* https://logging.apache.org/log4j/2.x/manual/customconfig.html#Example
* https://logging.apache.org/log4j/2.x/manual/customconfig.html#Configurator
] but not in [
* https://logging.apache.org/log4j/2.x/manual/customconfig.html#Hybrid
*
https://logging.apache.org/log4j/2.x/manual/customconfig.html#AddingToCurrent
].

Is this because it can/should not be used in those cases?

I would like do a hybrid configuration in which "configure(s) with a
configuration file but do(es) some additional programmatic configuration".
In addition I am wondering if I could use the configuration factory to
regenerate the logging context.
The idea is that the factory would retain custom information that would be
applied in the case of an automatic reload.
Is there a way to trigger an automatic reload?
Reply | Threaded
Open this post in threaded view
|

Re: ConfigurationBuilder in Programmatic Configuration

Ralph Goers
ConfiguratoinBiulder will create a full configuration. If you want to merge it with a configuration generated from a file you could use a CompositeConfiguration.  In that case you would do something like:


List<AbstractConfiguration> list = new ArrayList<>();
list.add(ctx.getConfiguration()); // Get existing file-based configuration.
List.add(builder.build()); // Use the builder to create an additional configuration.
ctx.setConfiguration(new CompositeConfiguration(list));  // Merge the configurations and set the resulting configuration as active.

Ralph


> On Nov 1, 2019, at 9:41 AM, Fred Eisele <[hidden email]> wrote:
>
> ref:
> https://logging.apache.org/log4j/2.x/manual/customconfig.html#ConfigurationBuilder
>
> The ConfigurationBuilder is demonstrated in [
> * https://logging.apache.org/log4j/2.x/manual/customconfig.html#Example
> * https://logging.apache.org/log4j/2.x/manual/customconfig.html#Configurator
> ] but not in [
> * https://logging.apache.org/log4j/2.x/manual/customconfig.html#Hybrid
> *
> https://logging.apache.org/log4j/2.x/manual/customconfig.html#AddingToCurrent
> ].
>
> Is this because it can/should not be used in those cases?
>
> I would like do a hybrid configuration in which "configure(s) with a
> configuration file but do(es) some additional programmatic configuration".
> In addition I am wondering if I could use the configuration factory to
> regenerate the logging context.
> The idea is that the factory would retain custom information that would be
> applied in the case of an automatic reload.
> Is there a way to trigger an automatic reload?



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]