You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by "Remko Popma (JIRA)" <ji...@apache.org> on 2016/08/19 01:52:20 UTC
[jira] [Comment Edited] (LOG4J2-1531) Change attribute and
component values from String to Object
[ https://issues.apache.org/jira/browse/LOG4J2-1531?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15427458#comment-15427458 ]
Remko Popma edited comment on LOG4J2-1531 at 8/19/16 1:52 AM:
--------------------------------------------------------------
Roger, would you be able to provide a patch for this (ideally with unit tests)?
was (Author: remkop@yahoo.com):
Roger, would you mind providing a patch for this (ideally with unit tests)?
> 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-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org