You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Fred Eisele <fr...@gmail.com> on 2019/11/01 16:41:20 UTC

ConfigurationBuilder in Programmatic Configuration

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?

Re: ConfigurationBuilder in Programmatic Configuration

Posted by Ralph Goers <ra...@dslextreme.com>.
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 <fr...@gmail.com> 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: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org