[logback-user] Avoid pre-initialization upon the first LoggerFactory.getILoggerFactory();

Brice Dutheil brice.dutheil at gmail.com
Mon Jun 13 09:24:24 UTC 2016


Hi David,

Thanks for the reply, but I’m speaking about 2 web-apps (i.e. 2 war files)
that are deployed by a single tomcat instance. That means I don’t have
access to the main and as it is a single JVM I cannot use the system
property, because both web-apps will now have the same value for app.name.

Cheers,
— Brice

On Fri, Jun 10, 2016 at 12:36 PM, David Roussel <nabble at diroussel.xsmail.com>
wrote:

Hi,
>
> There are two ways to deal with this.
>
> 1) Put your log initialisation at the top of your main() method, so
> nothing else can run first.
>
> 2) Specify the app name as a system property on the command line:
>
>   java -Dapp.name=MyApp -jar myappjar
>
> Thanks
>
> David
>
> On 10 Jun 2016, at 10:20, Brice Dutheil <brice.dutheil at gmail.com> wrote:
>
> Hi,
>
> I would like share a single log configuration for two web-apps that run on
> the same container. Yet I want each web-app to log in separate files.
>
> I tried different approach the best one is actually very close to some
> solution I later found on the FAQ :
> http://logback.qos.ch/faq.html#sharedConfiguration
>
> LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
> JoranConfigurator jc = new JoranConfigurator();
> jc.setContext(loggerContext);
> loggerContext.reset();
> loggerContext.setName(appName); // use ${CONTEXT_NAME} in logback.xml
> jc.doConfigure(Objects.requireNonNull(source, "Logback configuration is missing"));
>
> However for operation reasons we pass the configuration via the system
> property logback.configurationFile, so what happens is that the first
> call to LoggerFactory.getILoggerFactory() initialise the LoggerContext
> and creates files with non initialised variables.
>
> As I’m using the context name, the file names have default in their name
> (this is the default value of the context name), if using variable I get a
> filename with my-var-name_IS_UNDEFINED.
>
> *The question is :* Is there proper way anyway to avoid this
> pre-initialisation to avoid creating this empty file ?
>
> I didn’t found any way to hook in the org.slf4j.LoggerFactory or
> org.slf4j.impl.StaticLoggerBinder (of logback-classic).
>
> — Brice
>> _______________________________________________
> logback-user mailing list
> logback-user at qos.ch
> http://mailman.qos.ch/mailman/listinfo/logback-user
>
>
>
> _______________________________________________
> logback-user mailing list
> logback-user at qos.ch
> http://mailman.qos.ch/mailman/listinfo/logback-user
>
​
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/logback-user/attachments/20160613/bb4df63a/attachment-0001.html>


More information about the logback-user mailing list