Uploaded image for project: 'logback'
  1. logback
  2. LOGBACK-551

create a DelegateAppender which delegates all events to multiple child appenders

    XMLWordPrintable

Details

    • Icon: New Feature New Feature
    • Resolution: Unresolved
    • Icon: Major Major
    • None
    • None
    • logback-classic
    • None

    Description

      Hi,

      I'm using LogBack now since some time and got a config that suits me quite well, which i even modularized by merging multiple logback xml files to one and giving that as the configuration to logback. Thats needed because I am building a modular software productline with decentral configuration per module which have their own eclipse project.

      I have two default console appenders. One for System.out (level<=INFO) called "stdout" and another one for System.err (level>=WARN) called "stderr".
      On top of that I got two default log files. One for all the stuff that goes to both console appenders called "default" and another one for detailed error stacktraces called "error". I do that because I filter stacktraces for console but still want to have access to the complete stacktraces in another log file specific for that purpose. And beside those loggers my modules can create other file appenders like sql.log or messages.log and stuff.

      Now to my point: Because I have 4 appenders I almost always use together (2x console and 2x file), i have quite a lot of appender-refs I have to write on my logger definitions. To help with that, I would like to have an appender (called "common") which has the other 4 appenders as children like this:

      <appender name="common" class="...logback...DelegatingAppender">
      <appender-ref ref="stdout" />
      <appender-ref ref="stderr" />
      <appender-ref ref="default" />
      <appender-ref ref="error" />
      <!-- also nice would be to have a hidden appender that can't be directly used in loggers, but not actually required for my purposes -->
      <appender name="hiddenAndThusNameShouldNotBeNeeded" class="...SomeClass">
      <!-- ... some configuration ... -->
      </appender>
      </appender>

      With that I could either just put "common" on a logger to print to all 4 appenders or I would still have the flexibility to specify only one of those appers.
      I tried to implement this on my own, Implementing the appender class itself wasn't a problem, but I don't get how to make joran to understand the appender-ref and insert the delegate appender class into my DelegatingAppender via some setter. It would be nice if you could either include this as a feature into logback-classic or help me out writing it on my own.

      Attachments

        Activity

          People

            logback-dev Logback dev list
            subes subes
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: