<div dir="ltr"><div class="markdown-here-wrapper" style=""><p style="margin:0px 0px 1.2em!important">Hi,</p>
<p style="margin:0px 0px 1.2em!important">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.</p>
<p style="margin:0px 0px 1.2em!important">I tried different approach the best one is actually very close to some solution I later found on the FAQ : <a href="http://logback.qos.ch/faq.html#sharedConfiguration">http://logback.qos.ch/faq.html#sharedConfiguration</a></p>
<pre style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px"><code class="hljs language-java" style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;background-color:rgb(248,248,248);white-space:pre;overflow:auto;border-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em 0.7em;display:block!important;display:block;overflow-x:auto;padding:0.5em;color:rgb(209,217,225);background:rgb(71,73,73)">LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
JoranConfigurator jc = <span class="hljs-keyword" style="color:rgb(204,153,204)">new</span> JoranConfigurator();
jc.setContext(loggerContext);
loggerContext.reset();
loggerContext.setName(appName); <span class="hljs-comment" style="color:rgb(150,152,150);font-style:italic">// use ${CONTEXT_NAME} in logback.xml</span>
jc.doConfigure(Objects.requireNonNull(source, <span class="hljs-string" style="color:rgb(138,190,183)">"Logback configuration is missing"</span>));
</code></pre>
<p style="margin:0px 0px 1.2em!important">However for operation reasons we pass the configuration via the system property <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;background-color:rgb(248,248,248)">logback.configurationFile</code>, so what happens is that the first call to <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;background-color:rgb(248,248,248)">LoggerFactory.getILoggerFactory()</code> initialise the LoggerContext and creates files with non initialised variables.</p>
<p style="margin:0px 0px 1.2em!important">As I’m using the context name, the file names have <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;background-color:rgb(248,248,248)">default</code> in their name (this is the default value of the context name), if using variable I get a filename with <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;background-color:rgb(248,248,248)">my-var-name_IS_UNDEFINED</code>.</p>
<p style="margin:0px 0px 1.2em!important"><strong>The question is :</strong> Is there proper way anyway to avoid this pre-initialisation to avoid creating this empty file ?</p>
<p style="margin:0px 0px 1.2em!important">I didn’t found any way to hook in the <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;background-color:rgb(248,248,248)">org.slf4j.LoggerFactory</code> or <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;background-color:rgb(248,248,248)">org.slf4j.impl.StaticLoggerBinder</code> (of logback-classic).</p>
<p style="margin:0px 0px 1.2em!important">— Brice</p>
<div title="MDH:PGRpdj5IaSw8L2Rpdj48ZGl2Pjxicj48L2Rpdj48ZGl2Pkkgd291bGQgbGlrZSBzaGFyZSBhIHNp
bmdsZSBsb2cgY29uZmlndXJhdGlvbiBmb3IgdHdvIHdlYi1hcHBzIHRoYXQgcnVuIG9uIHRoZSBz
YW1lIGNvbnRhaW5lci4gWWV0IEkgd2FudCBlYWNoIHdlYi1hcHAgdG8gbG9nIGluI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