开发者

How do I add multiple appenders to my Custom Appender using groovy config?

开发者 https://www.devze.com 2023-04-02 02:04 出处:网络
I am converting my logback.xml file to groovy and am posed with this challenge of adding appenders to my custom appender!

I am converting my logback.xml file to groovy and am posed with this challenge of adding appenders to my custom appender!

Currently I do it like this:

<appender name="MyCustomAppender" class="url.MyCustomAppender">
    <param name="BufferSize" value="10000"/>
    <param name="Blocking" value="true"/>
    <appender-ref ref="FILE"/>
    <!-- <appender-ref ref="CONSOLE"/> -->
    <appender-ref ref="CONSOLE_ERR"/>
</appender>

I tried something like this with groovy but it fails:

   appender("MyCustomAppender", MyCustomAppender) {
开发者_开发技巧    BufferSize = 10000
    Blocking = true
    appender-ref('ref':"CONSOLE_ERR");
        appender-ref('ref':"FILE"); 
   }

I can't change the custom appender as it is in shared code, so that isn't a solution. I would just like to do the exact same thing that happens in xml, but in groovy.


Try this:

def consoleErrAppender = appenderList.find { it -> it.name == "CONSOLE_ERR" }
def fileAppender = appenderList.find { it -> it.name == "FILE" }

appender("MyCustomAppender", MyCustomAppender) {
    BufferSize = 10000
    Blocking = true
    appender = consoleErrAppender
    appender = fileAppender    
}

I suppose your MyCustomAppender implements the AppenderAttachable interface (or at least has a public void addAppender(Appender<E> newAppender) method).

0

精彩评论

暂无评论...
验证码 换一张
取 消