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

Roger Kapsi edited comment on LOG4J2-1531 at 8/19/16 10:55 PM:
---------------------------------------------------------------

So Clojure itself is Java 6+ compatible. I'm happy to contribute a DSL if 
you're looking for a configuration method that isn't as static as Java and as 
not as "detached" as XML/JSON/YAML/Properties. The beauty of Clojure is that it 
compiles down to bytecode, you get the benefits of a Compiler as your input 
validation and it remains dynamic. 

I've been referring to Java 8+ and Java lambdas as I don't know how familiar 
you're (the log4j2 dev community that is) with Clojure/Lisp. Java would be a 
little bit more static (even with lambdas) but there are simply things such as 
(this is Java):

{code:java}
(logger, level, marker, msg) -> logger.getName().equals("org.apache.MyClass")
    && level.equals(Level.ERROR)
    && msg != null && msg.contains("Hello, World!");
{code}

That cannot be expressed very elegantly in XML/JSON/YAML/Propertie and even it 
was possible, Log4J2's API simply doesn't allow it right now because every 
configuration value is assumed to be a String.

This ticket is about opening the door for non-String configuration values that 
can be passed into {{@Plugin}} and {{@PluginFactory}} which enables rich 
programmatic configuration from Java, Clojure, Scala, Kotlin, Groovy. The 
emphasis is on programmatic configuration. There is no interest on my end in 
parsing and object mapping of Strings ala XML, JSON, YAML, Properties.


was (Author: rkapsi):
So Clojure itself is Java 6+ compatible. I'm happy to contribute a DSL if 
you're looking for a configuration method that isn't as static as Java and as 
not as "detached" as XML/JSON/YAML/Properties. The beauty of Clojure is that it 
compiles down to bytecode, you get the benefits of a Compiler as your input 
validation and it remains dynamic. 

I've been referring to Java 8+ and Java lambdas as I don't know how familiar 
you're (the log4j2 dev community hat is) with Clojure/Lisp. Java would be a 
little bit more static (even with lambdas) but there are simply things such as:

{code:java}
(logger, level, marker, msg) -> logger.getName().equals("org.apache.MyClass")
    && level.equals(Level.ERROR)
    && msg != null && msg.contains("Hello, World!");
{code}

That cannot be expressed very elegantly in XML/JSON/YAML/Propertie and even it 
was possible, Log4J2's API simply doesn't allow it right now because every 
configuration value is assumed to be a String.

This ticket is about opening the door for non-String configuration values that 
can be passed into {{@Plugin}} and {{@PluginFactory}} which enables rich 
programmatic configuration from Java, Clojure, Scala, Kotlin, Groovy. The 
emphasis is on programmatic configuration. There is no interest on my end in 
parsing and object mapping of Strings ala XML, JSON, YAML, Properties.

> 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-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-dev-h...@logging.apache.org

Reply via email to