<div dir="ltr">Hi,<div><br></div><div style>I'm writing a logback appender that pushes errors to a remote API. It uses supporting classes like RestTemplate and HttpClient to talk to the API. </div><div style><br></div>
<div style>I initially tried to register the appender through a logback XML configuration, but I was warned that loggers named after the supporting classes would be suppressed because they were created during the logback configuration phase. Since those loggers are needed in other parts of the system, and multi-step initialisation didn't seem feasible, I had to revise the implementation.</div>
<div style><br></div><div style>The revised implementation programmatically registers the appender after the logback configuration phase, and it seems to work correctly. The issue is that I'm getting nested logging calls. For example, RestTemplate logs to SLF4J. If there is a failure in RestTemplate, it sends a logging event to SLF4J and therefore to logback, which goes to my appender, which will once again try to hit the RestTemplate. Some mechanism seems to be protecting against an infinite loop, since only four messages are logged, but I'm wondering if there's something I can do to prevent my appender from attempting to even try the nested call. MDC magic perhaps, assuming the same thread is making the nested call?</div>
<div style><br></div><div style>Any feedback would be appreciated.</div><div style><br></div><div style>Thanks,</div><div style>Emerson</div></div>