Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-1531

Change attribute and component values from String to Object

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 2.6.2
    • Fix Version/s: None
    • Component/s: Core
    • Labels:
      None

      Description

      I was looking into creating a ConfigurationFactory/Builder that is backed by a Clojure DSL. It works rather beautifully until I tried to create a filter that is backed by a Clojure function. There is literally no way to pass arbitrary objects into a PluginFactory. All component values and attributes are assumed to be Strings.

      (configuration
        (appender "stdout" "CONSOLE"
          (layout "PatternLayout"
            (attribute "pattern" "%d [%t] %-5level: %msg%n"))
          (filter "ClojureFilter"
            ;; This LoC doesn't work: addAttribute(key, value)
            ;; will store the toString() of the value. Bummer.
            ;; I'd the so easy and beautiful if it didn't.
            (attribute "fn" (fn [logger & more] (println logger)))))
        
        (logger "TestLogger" Level/INFO
          (appender-ref "rolling")
          (attribute "additivity" false))
        (root-logger Level/DEBUG 
          (appender-ref "rolling")))
      
      @Plugin(name = "ClojureFilter", category = Node.CATEGORY, elementType = Filter.ELEMENT_TYPE, printObject = true)
      class ClojureFilter extends AbstractFilter {
        @PluginFactory
        public static ClojureFilter createFilter(
            @PluginAttribute("fn") IFn fn, ...) {
      
           return new ClojureFilter(fn, ...);
        }
      }
      

        Attachments

        1. log4j2-1531-1.0.patch
          54 kB
          Roger Kapsi

          Issue Links

            Activity

              People

              • Assignee:
                rgoers Ralph Goers
                Reporter:
                rkapsi Roger Kapsi
              • Votes:
                0 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated: