[logback-user] Custom appender is being ignored
Zac Harvey
bitbythecron at gmail.com
Mon Jul 25 20:27:30 CEST 2022
Thank you Ceki! I called start() in the CatAppender constructor and
everything is now working. Are there recommended practices as to when (and
from where) to call start() and stop()? Thanks again so much!
Best,
Zac
On Mon, Jul 25, 2022 at 2:14 PM Ceki Gülcü <ceki at qos.ch> wrote:
> Hello Zac,
>
> AppenderBase will not invoke the append() method less the appender has
> the started flag set to true.
>
>
> --
> Ceki Gülcü
>
> Sponsoring SLF4J/logback/reload4j at https://github.com/sponsors/qos-ch
>
> On 7/25/2022 6:38 PM, Zac Harvey wrote:
> > Java 11 and logback-classic-1.2.11 here. I'm trying to write my own
> > custom appender and am following this Baeldung article
> > <https://www.baeldung.com/custom-logback-appender> to test it out.
> >
> > My *src/main/java/myapp/logging/CatAppender* appender (on the runtime
> > classpath):
> >
> > public class CatAppender extends AppenderBase<ILoggingEvent> {
> > @Override
> > protected void append(ILoggingEvent eventObject) {
> > System.out.println("meow");
> > }
> > }
> >
> > My *src/main/resources/logback.xml*:
> >
> > <?xml version="1.0" encoding="UTF-8"?>
> > <configuration debug="true">
> >
> > <appender name="cat" class="myapp.logging.CatAppender"/>
> >
> > <root level="info">
> > <appender-ref ref="cat" />
> > </root>
> >
> > </configuration>
> >
> > In my *build.gradle* I specify to use logback and Lombok:
> >
> > plugins {
> > id "io.freefair.lombok" version '6.4.0'
> > }
> >
> > dependencies {
> > implementation (
> > 'ch.qos.logback:logback-classic:1.2.11'
> > ,'org.projectlombok:lombok:1.18.16'
> > )
> > }
> >
> > And then in my Java code I use Lombok to inject an SLF4J logger like so:
> >
> > @Slf4j
> > public class SomethingDoer {
> >
> > public void doSomething() {
> > log.info <http://log.info>("this should invoke the
> CatAppender...");
> > }
> >
> > }
> >
> > But when *SomethingDoer#doSomething()* runs, I don't see a meow printed
> > to my STDOUT console. Have I wired anything up incorrectly here?
> >
> _______________________________________________
> logback-user mailing list
> logback-user at qos.ch
> http://mailman.qos.ch/mailman/listinfo/logback-user
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/logback-user/attachments/20220725/21f68e2d/attachment.html>
More information about the logback-user
mailing list