Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 321A4200B69 for ; Sat, 20 Aug 2016 12:27:22 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 30A69160ABB; Sat, 20 Aug 2016 10:27:22 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 7876B160AAA for ; Sat, 20 Aug 2016 12:27:21 +0200 (CEST) Received: (qmail 60539 invoked by uid 500); 20 Aug 2016 10:27:20 -0000 Mailing-List: contact log4j-dev-help@logging.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Log4J Developers List" Reply-To: "Log4J Developers List" Delivered-To: mailing list log4j-dev@logging.apache.org Received: (qmail 60530 invoked by uid 99); 20 Aug 2016 10:27:20 -0000 Received: from arcas.apache.org (HELO arcas) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 20 Aug 2016 10:27:20 +0000 Received: from arcas.apache.org (localhost [127.0.0.1]) by arcas (Postfix) with ESMTP id 755B52C0152 for ; Sat, 20 Aug 2016 10:27:20 +0000 (UTC) Date: Sat, 20 Aug 2016 10:27:20 +0000 (UTC) From: =?utf-8?Q?Mikael_St=C3=A5ldal_=28JIRA=29?= To: log4j-dev@logging.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (LOG4J2-1531) Change attribute and component values from String to Object MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Sat, 20 Aug 2016 10:27:22 -0000 [ https://issues.apache.org/jira/browse/LOG4J2-1531?page=3Dcom.atlassia= n.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=3D154= 29322#comment-15429322 ]=20 Mikael St=C3=A5ldal commented on LOG4J2-1531: ---------------------------------------- I think that this is a misuse of the {{@Plugin}} mechanism, it is designed = for configuration files rather than programmatic configuration. If we want rich programmatic configuration, I think we should bypass the re= flection based {{@Plugin}} mechanism altogether. What about overloading the add methods in {{ConfigurationBuilder}} to also = take a programmaticly constructed Filter, Layout, Appender instances? You c= an then create ad-hoc Filters, Layouts, Appenders only for this purpose, an= d they should not need to have any annotations. We can also create some Single Abstract Method abstract Filters, Layouts, A= ppenders for this purpuse to make it possible to use Java 8 lambdas conveni= ently. > 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 fi= lter that is backed by a Clojure function. There is literally no way to pa= ss arbitrary objects into a PluginFactory. All component values and attribu= tes 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))))) > =20 > (logger "TestLogger" Level/INFO > (appender-ref "rolling") > (attribute "additivity" false)) > (root-logger Level/DEBUG=20 > (appender-ref "rolling"))) > {code} > {code:java} > @Plugin(name =3D "ClojureFilter", category =3D Node.CATEGORY, elementType= =3D Filter.ELEMENT_TYPE, printObject =3D 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