<div dir="ltr"><div>Thanks again! If you don't mind, one <b>final</b> follow-up question regarding stop():</div><div><br></div><div>Do I need to wire my CatAppender#stop() calls up to any lifecycle hooks/calls called by logback/SLF4J itself, or is the idea that the <b>application</b> can stop an appender programmatically if the application desires to stop using it (stop logging) at any point?</div><div><br></div><div>In my case, I can't think of a reason to expose the AppenderBase#stop() from the outside world (application) and allow the app to stop logging/appending. But should I override an AppenderBase method anyways, and call stop() from inside of it, and logback/SLF4J will call that overridden method at shutdown? Or is it safe in my case to just <i>not</i> call stop() at all, from anywhere inside the CatAppender?</div><div><br></div><div>Thanks again so much!<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jul 26, 2022 at 5:37 AM Ceki Gülcü <<a href="mailto:ceki@qos.ch">ceki@qos.ch</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"><br>
The start() method is akin to a constructor check.<br>
<br>
The start method should check whether all required parameters have been<br>
passed during configuration. If required parameters are missing, the<br>
appender should refuse to start and warn the user.<br>
<br>
The stop() method should release resources if any.<br>
<br>
-- <br>
Ceki Gülcü<br>
<br>
Sponsoring SLF4J/logback/reload4j at <a href="https://github.com/sponsors/qos-ch" rel="noreferrer" target="_blank">https://github.com/sponsors/qos-ch</a><br>
<br>
<br>
On 7/25/2022 8:27 PM, Zac Harvey wrote:<br>
> Thank you Ceki! I called start() in the CatAppender constructor and<br>
> everything is now working. Are there recommended practices as to when<br>
> (and from where) to call start() and stop()? Thanks again so much!<br>
> <br>
> Best,<br>
> Zac<br>
> <br>
> On Mon, Jul 25, 2022 at 2:14 PM Ceki Gülcü <<a href="mailto:ceki@qos.ch" target="_blank">ceki@qos.ch</a><br>
> <mailto:<a href="mailto:ceki@qos.ch" target="_blank">ceki@qos.ch</a>>> wrote:<br>
> <br>
> Hello Zac,<br>
> <br>
> AppenderBase will not invoke the append() method less the appender has<br>
> the started flag set to true.<br>
> <br>
> <br>
> -- <br>
> Ceki Gülcü<br>
> <br>
> Sponsoring SLF4J/logback/reload4j at<br>
> <a href="https://github.com/sponsors/qos-ch" rel="noreferrer" target="_blank">https://github.com/sponsors/qos-ch</a> <<a href="https://github.com/sponsors/qos-ch" rel="noreferrer" target="_blank">https://github.com/sponsors/qos-ch</a>><br>
> <br>
> On 7/25/2022 6:38 PM, Zac Harvey wrote:<br>
> > Java 11 and logback-classic-1.2.11 here. I'm trying to write my own<br>
> > custom appender and am following this Baeldung article<br>
> > <<a href="https://www.baeldung.com/custom-logback-appender" rel="noreferrer" target="_blank">https://www.baeldung.com/custom-logback-appender</a><br>
> <<a href="https://www.baeldung.com/custom-logback-appender" rel="noreferrer" target="_blank">https://www.baeldung.com/custom-logback-appender</a>>> to test it out.<br>
> ><br>
> > My *src/main/java/myapp/logging/CatAppender* appender (on the runtime<br>
> > classpath):<br>
> ><br>
> > public class CatAppender extends AppenderBase<ILoggingEvent> {<br>
> > @Override<br>
> > protected void append(ILoggingEvent eventObject) {<br>
> > System.out.println("meow");<br>
> > }<br>
> > }<br>
> ><br>
> > My *src/main/resources/logback.xml*:<br>
> ><br>
> > <?xml version="1.0" encoding="UTF-8"?><br>
> > <configuration debug="true"><br>
> ><br>
> > <appender name="cat" class="myapp.logging.CatAppender"/><br>
> ><br>
> > <root level="info"><br>
> > <appender-ref ref="cat" /><br>
> > </root><br>
> ><br>
> > </configuration><br>
> ><br>
> > In my *build.gradle* I specify to use logback and Lombok:<br>
> ><br>
> > plugins {<br>
> > id "io.freefair.lombok" version '6.4.0'<br>
> > }<br>
> ><br>
> > dependencies {<br>
> > implementation (<br>
> > 'ch.qos.logback:logback-classic:1.2.11'<br>
> > ,'org.projectlombok:lombok:1.18.16'<br>
> > )<br>
> > }<br>
> ><br>
> > And then in my Java code I use Lombok to inject an SLF4J logger<br>
> like so:<br>
> ><br>
> > @Slf4j<br>
> > public class SomethingDoer {<br>
> ><br>
> > public void doSomething() {<br>
> > <a href="http://log.info" rel="noreferrer" target="_blank">log.info</a> <<a href="http://log.info" rel="noreferrer" target="_blank">http://log.info</a>> <<a href="http://log.info" rel="noreferrer" target="_blank">http://log.info</a><br>
> <<a href="http://log.info" rel="noreferrer" target="_blank">http://log.info</a>>>("this should invoke the CatAppender...");<br>
> > }<br>
> ><br>
> > }<br>
> ><br>
> > But when *SomethingDoer#doSomething()* runs, I don't see a meow<br>
> printed<br>
> > to my STDOUT console. Have I wired anything up incorrectly here?<br>
> ><br>
> _______________________________________________<br>
> logback-user mailing list<br>
> <a href="mailto:logback-user@qos.ch" target="_blank">logback-user@qos.ch</a> <mailto:<a href="mailto:logback-user@qos.ch" target="_blank">logback-user@qos.ch</a>><br>
> <a href="http://mailman.qos.ch/mailman/listinfo/logback-user" rel="noreferrer" target="_blank">http://mailman.qos.ch/mailman/listinfo/logback-user</a><br>
> <<a href="http://mailman.qos.ch/mailman/listinfo/logback-user" rel="noreferrer" target="_blank">http://mailman.qos.ch/mailman/listinfo/logback-user</a>><br>
> <br>
> <br>
> _______________________________________________<br>
> logback-user mailing list<br>
> <a href="mailto:logback-user@qos.ch" target="_blank">logback-user@qos.ch</a><br>
> <a href="http://mailman.qos.ch/mailman/listinfo/logback-user" rel="noreferrer" target="_blank">http://mailman.qos.ch/mailman/listinfo/logback-user</a><br>
<br>
-- <br>
Ceki Gülcü<br>
<br>
Sponsoring SLF4J/logback/reload4j at <a href="https://github.com/sponsors/qos-ch" rel="noreferrer" target="_blank">https://github.com/sponsors/qos-ch</a><br>
_______________________________________________<br>
logback-user mailing list<br>
<a href="mailto:logback-user@qos.ch" target="_blank">logback-user@qos.ch</a><br>
<a href="http://mailman.qos.ch/mailman/listinfo/logback-user" rel="noreferrer" target="_blank">http://mailman.qos.ch/mailman/listinfo/logback-user</a></blockquote></div>