<html><head></head><body><div class="ydpddea8f1eyahoo-style-wrap" style="font-family:Helvetica Neue, Helvetica, Arial, sans-serif;font-size:13px;"><div></div>
<div dir="ltr" data-setdir="false">Did you read my reply[1]? You shouldn't need to explicitly call `start()` nor `stop()` on your Appender implementation.</div><div dir="ltr" data-setdir="false"><br></div><div dir="ltr" data-setdir="false">Likely something is wrong with your project setup - you can start investigating by trying to run my working project, and comparing it with yours to understand why yours didn't work.<br></div><div dir="ltr" data-setdir="false"><br></div><div dir="ltr" data-setdir="false">[1] <a href="http://mailman.qos.ch/pipermail/logback-user/2022-July/005215.html" rel="nofollow" target="_blank" class="">http://mailman.qos.ch/pipermail/logback-user/2022-July/005215.html</a></div><div><br></div><div><br></div><div><br></div><div><br></div>
</div><div id="ydp388a0d8ayahoo_quoted_9391883276" class="ydp388a0d8ayahoo_quoted">
<div style="font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:13px;color:#26282a;">
<div>
On Tuesday, 26 July 2022 at 20:22:07 GMT+8, Zac Harvey <bitbythecron@gmail.com> wrote:
</div>
<div><br></div>
<div><br></div>
<div><div id="ydp388a0d8ayiv6229637332"><div><div dir="ltr"><div>Thanks again! If you don't mind, one <b>final</b> follow-up question regarding stop():</div><div><br clear="none"></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 clear="none"></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 clear="none"></div><div>Thanks again so much!<br clear="none"></div></div><br clear="none"><div id="ydp388a0d8ayiv6229637332yqt26769" class="ydp388a0d8ayiv6229637332yqt2355163137"><div class="ydp388a0d8ayiv6229637332gmail_quote"><div dir="ltr" class="ydp388a0d8ayiv6229637332gmail_attr">On Tue, Jul 26, 2022 at 5:37 AM Ceki Gülcü <<a shape="rect" href="mailto:ceki@qos.ch" rel="nofollow" target="_blank">ceki@qos.ch</a>> wrote:<br clear="none"></div><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex;" class="ydp388a0d8ayiv6229637332gmail_quote"><br clear="none">
The start() method is akin to a constructor check.<br clear="none">
<br clear="none">
The start method should check whether all required parameters have been<br clear="none">
passed during configuration. If required parameters are missing, the<br clear="none">
appender should refuse to start and warn the user.<br clear="none">
<br clear="none">
The stop() method should release resources if any.<br clear="none">
<br clear="none">
-- <br clear="none">
Ceki Gülcü<br clear="none">
<br clear="none">
Sponsoring SLF4J/logback/reload4j at <a shape="rect" href="https://github.com/sponsors/qos-ch" rel="nofollow" target="_blank">https://github.com/sponsors/qos-ch</a><br clear="none">
<br clear="none">
<br clear="none">
On 7/25/2022 8:27 PM, Zac Harvey wrote:<br clear="none">
> Thank you Ceki! I called start() in the CatAppender constructor and<br clear="none">
> everything is now working. Are there recommended practices as to when<br clear="none">
> (and from where) to call start() and stop()? Thanks again so much!<br clear="none">
> <br clear="none">
> Best,<br clear="none">
> Zac<br clear="none">
> <br clear="none">
> On Mon, Jul 25, 2022 at 2:14 PM Ceki Gülcü <<a shape="rect" href="mailto:ceki@qos.ch" rel="nofollow" target="_blank">ceki@qos.ch</a><br clear="none">
> <mailto:<a shape="rect" href="mailto:ceki@qos.ch" rel="nofollow" target="_blank">ceki@qos.ch</a>>> wrote:<br clear="none">
> <br clear="none">
> Hello Zac,<br clear="none">
> <br clear="none">
> AppenderBase will not invoke the append() method less the appender has<br clear="none">
> the started flag set to true.<br clear="none">
> <br clear="none">
> <br clear="none">
> -- <br clear="none">
> Ceki Gülcü<br clear="none">
> <br clear="none">
> Sponsoring SLF4J/logback/reload4j at<br clear="none">
> <a shape="rect" href="https://github.com/sponsors/qos-ch" rel="nofollow" target="_blank">https://github.com/sponsors/qos-ch</a> <<a shape="rect" href="https://github.com/sponsors/qos-ch" rel="nofollow" target="_blank">https://github.com/sponsors/qos-ch</a>><br clear="none">
> <br clear="none">
> On 7/25/2022 6:38 PM, Zac Harvey wrote:<br clear="none">
> > Java 11 and logback-classic-1.2.11 here. I'm trying to write my own<br clear="none">
> > custom appender and am following this Baeldung article<br clear="none">
> > <<a shape="rect" href="https://www.baeldung.com/custom-logback-appender" rel="nofollow" target="_blank">https://www.baeldung.com/custom-logback-appender</a><br clear="none">
> <<a shape="rect" href="https://www.baeldung.com/custom-logback-appender" rel="nofollow" target="_blank">https://www.baeldung.com/custom-logback-appender</a>>> to test it out.<br clear="none">
> ><br clear="none">
> > My *src/main/java/myapp/logging/CatAppender* appender (on the runtime<br clear="none">
> > classpath):<br clear="none">
> ><br clear="none">
> > public class CatAppender extends AppenderBase<ILoggingEvent> {<br clear="none">
> > @Override<br clear="none">
> > protected void append(ILoggingEvent eventObject) {<br clear="none">
> > System.out.println("meow");<br clear="none">
> > }<br clear="none">
> > }<br clear="none">
> ><br clear="none">
> > My *src/main/resources/logback.xml*:<br clear="none">
> ><br clear="none">
> > <?xml version="1.0" encoding="UTF-8"?><br clear="none">
> > <configuration debug="true"><br clear="none">
> ><br clear="none">
> > <appender name="cat" class="myapp.logging.CatAppender"/><br clear="none">
> ><br clear="none">
> > <root level="info"><br clear="none">
> > <appender-ref ref="cat" /><br clear="none">
> > </root><br clear="none">
> ><br clear="none">
> > </configuration><br clear="none">
> ><br clear="none">
> > In my *build.gradle* I specify to use logback and Lombok:<br clear="none">
> ><br clear="none">
> > plugins {<br clear="none">
> > id "io.freefair.lombok" version '6.4.0'<br clear="none">
> > }<br clear="none">
> ><br clear="none">
> > dependencies {<br clear="none">
> > implementation (<br clear="none">
> > 'ch.qos.logback:logback-classic:1.2.11'<br clear="none">
> > ,'org.projectlombok:lombok:1.18.16'<br clear="none">
> > )<br clear="none">
> > }<br clear="none">
> ><br clear="none">
> > And then in my Java code I use Lombok to inject an SLF4J logger<br clear="none">
> like so:<br clear="none">
> ><br clear="none">
> > @Slf4j<br clear="none">
> > public class SomethingDoer {<br clear="none">
> ><br clear="none">
> > public void doSomething() {<br clear="none">
> > <a shape="rect" href="http://log.info" rel="nofollow" target="_blank">log.info</a> <<a shape="rect" href="http://log.info" rel="nofollow" target="_blank">http://log.info</a>> <<a shape="rect" href="http://log.info" rel="nofollow" target="_blank">http://log.info</a><br clear="none">
> <<a shape="rect" href="http://log.info" rel="nofollow" target="_blank">http://log.info</a>>>("this should invoke the CatAppender...");<br clear="none">
> > }<br clear="none">
> ><br clear="none">
> > }<br clear="none">
> ><br clear="none">
> > But when *SomethingDoer#doSomething()* runs, I don't see a meow<br clear="none">
> printed<br clear="none">
> > to my STDOUT console. Have I wired anything up incorrectly here?<br clear="none">
> ><br clear="none">
> _______________________________________________<br clear="none">
> logback-user mailing list<br clear="none">
> <a shape="rect" href="mailto:logback-user@qos.ch" rel="nofollow" target="_blank">logback-user@qos.ch</a> <mailto:<a shape="rect" href="mailto:logback-user@qos.ch" rel="nofollow" target="_blank">logback-user@qos.ch</a>><br clear="none">
> <a shape="rect" href="http://mailman.qos.ch/mailman/listinfo/logback-user" rel="nofollow" target="_blank">http://mailman.qos.ch/mailman/listinfo/logback-user</a><br clear="none">
> <<a shape="rect" href="http://mailman.qos.ch/mailman/listinfo/logback-user" rel="nofollow" target="_blank">http://mailman.qos.ch/mailman/listinfo/logback-user</a>><br clear="none">
> <br clear="none">
> <br clear="none">
> _______________________________________________<br clear="none">
> logback-user mailing list<br clear="none">
> <a shape="rect" href="mailto:logback-user@qos.ch" rel="nofollow" target="_blank">logback-user@qos.ch</a><br clear="none">
> <a shape="rect" href="http://mailman.qos.ch/mailman/listinfo/logback-user" rel="nofollow" target="_blank">http://mailman.qos.ch/mailman/listinfo/logback-user</a><br clear="none">
<br clear="none">
-- <br clear="none">
Ceki Gülcü<br clear="none">
<br clear="none">
Sponsoring SLF4J/logback/reload4j at <a shape="rect" href="https://github.com/sponsors/qos-ch" rel="nofollow" target="_blank">https://github.com/sponsors/qos-ch</a><br clear="none">
_______________________________________________<br clear="none">
logback-user mailing list<br clear="none">
<a shape="rect" href="mailto:logback-user@qos.ch" rel="nofollow" target="_blank">logback-user@qos.ch</a><br clear="none">
<a shape="rect" href="http://mailman.qos.ch/mailman/listinfo/logback-user" rel="nofollow" target="_blank">http://mailman.qos.ch/mailman/listinfo/logback-user</a></blockquote></div></div>
</div></div><div class="ydp388a0d8ayqt2355163137" id="ydp388a0d8ayqt02189">_______________________________________________<br clear="none">logback-user mailing list<br clear="none"><a shape="rect" href="mailto:logback-user@qos.ch" rel="nofollow" target="_blank">logback-user@qos.ch</a><br clear="none"><a shape="rect" href="http://mailman.qos.ch/mailman/listinfo/logback-user" rel="nofollow" target="_blank">http://mailman.qos.ch/mailman/listinfo/logback-user</a></div></div>
</div>
</div></body></html>