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 Jochen Wiedmann <jo...@gmail.com> on 2016/06/17 08:41:42 UTC
Multiple instances of log4j2.xml
Hi,
I have an application (more precisely: a war file), which is deployed
identically on the same application server. (Think multi temancy),
Now, in Log4j 1, I handled that situation quite easily, like this:
final String uri = tenantName + "/log4j.xml";
final URL url = ClassLoader.getResource(uri);
if (uri == null) {
throw new IllegalStateException("Unable to locate logging
configuration: " + uri);
}
DOMConfigurator.configure(url);
Or, in other words: For every tenant, I have a directory for
configuration files, including log4j.xml.
Simple, quick, and worked absolutely reliable.
But, how do I get this to work with log4j2?
Thanks,
Jochen
--
The next time you hear: "Don't reinvent the wheel!"
http://www.keystonedevelopment.co.uk/wp-content/uploads/2014/10/evolution-of-the-wheel-300x85.jpg
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: Multiple instances of log4j2.xml
Posted by Ralph Goers <ra...@dslextreme.com>.
Configuration is not part of the public API - it is very implementation specific. So Configurator is part of log4j-core. However, we expect it to be used by applications so it is one of the classes in core where we try to maintain binary compatibility.
Ralph
> On Jun 17, 2016, at 6:15 AM, Jochen Wiedmann <jo...@gmail.com> wrote:
>
> On Fri, Jun 17, 2016 at 3:07 PM, Ralph Goers <ra...@dslextreme.com> wrote:
>> You would use Configurator.initialize(“MyContextName”, this.getClass().getClassLoader(), uri);
>>
>> The classLoader value can be null.
>
> Thanks, Ralph. One question, though:
>
> The class Configurator is not present on
>
> http://logging.apache.org/log4j/2.x/log4j-api/apidocs/index.html
>
> Hence, it doesn't seem to be a part of the public API?
>
> Jochen
>
>
> --
> The next time you hear: "Don't reinvent the wheel!"
>
> http://www.keystonedevelopment.co.uk/wp-content/uploads/2014/10/evolution-of-the-wheel-300x85.jpg
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: Multiple instances of log4j2.xml
Posted by Matt Sicker <bo...@gmail.com>.
Configurator is in log4j-core.
On 17 June 2016 at 08:15, Jochen Wiedmann <jo...@gmail.com> wrote:
> On Fri, Jun 17, 2016 at 3:07 PM, Ralph Goers <ra...@dslextreme.com>
> wrote:
> > You would use Configurator.initialize(“MyContextName”,
> this.getClass().getClassLoader(), uri);
> >
> > The classLoader value can be null.
>
> Thanks, Ralph. One question, though:
>
> The class Configurator is not present on
>
> http://logging.apache.org/log4j/2.x/log4j-api/apidocs/index.html
>
> Hence, it doesn't seem to be a part of the public API?
>
> Jochen
>
>
> --
> The next time you hear: "Don't reinvent the wheel!"
>
>
> http://www.keystonedevelopment.co.uk/wp-content/uploads/2014/10/evolution-of-the-wheel-300x85.jpg
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>
--
Matt Sicker <bo...@gmail.com>
Re: Multiple instances of log4j2.xml
Posted by Jochen Wiedmann <jo...@gmail.com>.
On Fri, Jun 17, 2016 at 3:07 PM, Ralph Goers <ra...@dslextreme.com> wrote:
> You would use Configurator.initialize(“MyContextName”, this.getClass().getClassLoader(), uri);
>
> The classLoader value can be null.
Thanks, Ralph. One question, though:
The class Configurator is not present on
http://logging.apache.org/log4j/2.x/log4j-api/apidocs/index.html
Hence, it doesn't seem to be a part of the public API?
Jochen
--
The next time you hear: "Don't reinvent the wheel!"
http://www.keystonedevelopment.co.uk/wp-content/uploads/2014/10/evolution-of-the-wheel-300x85.jpg
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: Multiple instances of log4j2.xml
Posted by Ralph Goers <ra...@dslextreme.com>.
I would probably use tenantName for the context name.
Ralph
> On Jun 17, 2016, at 6:07 AM, Ralph Goers <ra...@dslextreme.com> wrote:
>
> You would use Configurator.initialize(“MyContextName”, this.getClass().getClassLoader(), uri);
>
> The classLoader value can be null.
>
> Ralph
>
>> On Jun 17, 2016, at 1:41 AM, Jochen Wiedmann <jo...@gmail.com> wrote:
>>
>> Hi,
>>
>> I have an application (more precisely: a war file), which is deployed
>> identically on the same application server. (Think multi temancy),
>> Now, in Log4j 1, I handled that situation quite easily, like this:
>>
>> final String uri = tenantName + "/log4j.xml";
>> final URL url = ClassLoader.getResource(uri);
>> if (uri == null) {
>> throw new IllegalStateException("Unable to locate logging
>> configuration: " + uri);
>> }
>> DOMConfigurator.configure(url);
>>
>> Or, in other words: For every tenant, I have a directory for
>> configuration files, including log4j.xml.
>> Simple, quick, and worked absolutely reliable.
>>
>> But, how do I get this to work with log4j2?
>>
>> Thanks,
>>
>> Jochen
>>
>> --
>> The next time you hear: "Don't reinvent the wheel!"
>>
>> http://www.keystonedevelopment.co.uk/wp-content/uploads/2014/10/evolution-of-the-wheel-300x85.jpg
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>>
>>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: Multiple instances of log4j2.xml
Posted by Ralph Goers <ra...@dslextreme.com>.
You would use Configurator.initialize(“MyContextName”, this.getClass().getClassLoader(), uri);
The classLoader value can be null.
Ralph
> On Jun 17, 2016, at 1:41 AM, Jochen Wiedmann <jo...@gmail.com> wrote:
>
> Hi,
>
> I have an application (more precisely: a war file), which is deployed
> identically on the same application server. (Think multi temancy),
> Now, in Log4j 1, I handled that situation quite easily, like this:
>
> final String uri = tenantName + "/log4j.xml";
> final URL url = ClassLoader.getResource(uri);
> if (uri == null) {
> throw new IllegalStateException("Unable to locate logging
> configuration: " + uri);
> }
> DOMConfigurator.configure(url);
>
> Or, in other words: For every tenant, I have a directory for
> configuration files, including log4j.xml.
> Simple, quick, and worked absolutely reliable.
>
> But, how do I get this to work with log4j2?
>
> Thanks,
>
> Jochen
>
> --
> The next time you hear: "Don't reinvent the wheel!"
>
> http://www.keystonedevelopment.co.uk/wp-content/uploads/2014/10/evolution-of-the-wheel-300x85.jpg
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org