[ https://issues.apache.org/jira/browse/LOG4J2-1531?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15428073#comment-15428073 ]
Roger Kapsi commented on LOG4J2-1531: ------------------------------------- Conceptually speaking... {code:java} Component#value to Object Component#attributes to Map<String, Object> Node#value to Object Node#attributes to Map<String, Object> DefaultComponentBuilder#addAttribute(String, k) to retain the object value of k instead of toString'ing it {code} And from there are few rabbit holes. That is probably an API breaking change. Instead of that maybe retain the existing "string view" of these objects and provide new accessors for the raw values. The PluginAttribute (and a few others) could have a new property that tells it to use the raw value instead of the toString() view. Keep in mind this is only relevant for programmatic configuration. Instead of the Clojure DSL example maybe something like this: {code:java} @Plugin(name = "JavaFunctionFilter", category = Node.CATEGORY, elementType = Filter.ELEMENT_TYPE, printObject = true) class JavaFunctionFilter extends AbstractFilter { @PluginFactory public static JavaFunctionFilter createFilter( @PluginAttribute("fn") Function<LogEvent, Boolean> fn, ...) { return new JavaFunctionFilter(fn, ...); } } ConfigurationBuilder<BuiltConfiguration> builder = ConfigurationBuilderFactory.newConfigurationBuilder(); builder.add(builder.newFilter("JavaFunctionFilter", Filter.Result.DENY, Filter.Result.NEUTRAL) .addAttribute("fn", (event) -> event.getLoggerName().equals("org.apache.Foo"))); {code} > Change attribute and component values from String to Object > ----------------------------------------------------------- > > Key: LOG4J2-1531 > URL: https://issues.apache.org/jira/browse/LOG4J2-1531 > Project: Log4j 2 > Issue Type: Improvement > Components: Core > Affects Versions: 2.6.2 > Reporter: Roger Kapsi > > 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. > {code:java} > (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"))) > {code} > {code:java} > @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, ...); > } > } > {code} -- This message was sent by Atlassian JIRA (v6.3.4#6332) --------------------------------------------------------------------- To unsubscribe, e-mail: log4j-dev-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-dev-h...@logging.apache.org