logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Roger Kapsi (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (LOG4J2-1531) Change attribute and component values from String to Object
Date Sun, 21 Aug 2016 12:46:20 GMT

    [ https://issues.apache.org/jira/browse/LOG4J2-1531?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15429704#comment-15429704
] 

Roger Kapsi commented on LOG4J2-1531:
-------------------------------------

I looked at {{@PluginElement}} et al. It's just a deferral to {{@Plugin}} and a few other
types that get their values again via {{addAttribute()}} which are strings.

Please notice that I'm not looking for a replacement for attributes or elements. The title
of this ticket does say to change the value type of attributes but that was before I dug deeper
into the implementation of it. The patch I submitted proposes a new {{add_ARG_ument(String,
Object)}} method along with a new {{@Plugin_ARG_ument}} annotation that doesn't interfere
with attributes or elements. It just allows plugin developers to pass arbitrary objects into
their {{@PluginFactory}}. The latter is desirable for programmatic configuration. Be it plain
Java or some other lang. I have mentioned Lamdas a lot as they're as arbitrary as it gets
but it applies equally well to other objects. Either because they can't or it's simply not
desirable. 

Adding methods such as {{add(Appender)}} to the configuration builder works (and you should
probably do it) but it doesn't necessarily facilitate a standard way of constructing things.
Speaking in terms of a DSL it's not necessarily something you want. You want a standard way
of construction with arbitrary arguments and you have a nice builder+plugin system for that.
It's only missing that one feature.

I have now solved the problem with a few hundred LoC of using a facade pattern, inheritance
and overriding some methods. It's sensitive to upstream changes but it works. I wish it wasn't
necessary though.

Please let me know when you've figured out the essence of this ticket. I'm happy to iterate
on it but attributes and elements aren't it and I don't want to go in circles on it.


> 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
>         Attachments: log4j2-1531-1.0.patch
>
>
> 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


Mime
View raw message