<div dir="ltr"><div>Hello,</div><div><br></div><div>I'm using slf4j with logback implementation. We have some critical
system properties that are used to configure logback and I want
developers to explicitly set them before they call
`LoggerFactory.getLogger()`. I want to throw an exception if the properties are not set.<b> </b>Below is my logback setup: <br></div><div><br></div><div>The `logback.xml` only has one line of
configuration which is a ContextListener: `<contextListener
class="com.company.server.logging.LogbackConfigurator" />`. The
context listener extends `ContextAwareBase` and implements
`LoggerContextListener` and `LifeCycle`. I programmatically configure logback layouts based on the system properties that I mentioned in the previous emails and if the properties are not set, I want to fail the application from starting. I tried to add a `StatusListener` which throws a runtime exception when `addStatusEvent` adds an error status.
However, the exception is caught by SLF4J in (in `org.slf4j.impl.StaticLoggerBinder#init`) and is swallowed. Does anyone have suggestions on how to mitigate this issue?</div><div><br></div><div>Thanks</div><font color="#888888"><div>Shawn</div></font></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, May 11, 2021 at 9:41 PM Shawn Song <<a href="mailto:mr.song.shawn@gmail.com">mr.song.shawn@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Hi,</div><div><br></div><div>I'm using slf4j with logback implementation. We have some critical system properties that are used to configure logback and I want developers to explicitly set them before they call `LoggerFactory.getLogger()`. I want to throw an exception if the properties are not set. I have tried to throw the exception from logback `StatusListener` but SLF4J catches all exceptions during its initialization (in org.slf4j.impl.StaticLoggerBinder#init). I know I can check the values of those properties at the start of the application but because they are purely used to configure logback, so I want to keep it inside the configuration code. Is there any way to stop SLF4J from catching the exceptions?</div><div><br></div><div>Thanks</div><div>Shawn<br></div></div>
</blockquote></div>