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

Robert Ross edited comment on LOG4J2-1686 at 4/24/18 1:04 PM:
--------------------------------------------------------------

The documentation for {{ScriptAppenderSelector}} is still wrong on the website. 
 It leaves a LOT to be desired.  Even the corrected documentation in these 
comments doesn't seem to work right.  The relationship between the return value 
from the script and the {{Appender}} in the {{AppenderSet}} is confusing and 
almost totally undocumented.  For example, I have this:
{code:xml}
<ScriptAppenderSelector name="ArchDependentAppender">
        <Script language="JavaScript">
                <![CDATA[
                        try{
                                load("nashorn:mozilla_compat.js");
                        } catch(e) {}
                        importPackage(java.lang);
                        System.getProperty("os.name").search("Windows") > -1 ? 
"WindowsAppender" : "UnixAppender";
                ]]>
        </Script>
        <AppenderSet>
                <FileAppender name="WindowsAppender">
                        <PatternLayout>
                                <Pattern>${appenderPatternLayout}</Pattern>
                        </PatternLayout>
                </FileAppender>
                <SyslogAppender name="UnixAppender" 
                                                advertise="true" 
                                                facility="LOCAL1" 
                                                format="RFC5424" 
                                                host="localhost" 
                                                port="514" 
                                                protocol="TCP" 
                                                newLine="true" />
        </AppenderSet>
</ScriptAppenderSelector>
{code}
 Which, from what I can tell, *should* work because the names of the 
{{Appender}} in the {{AppenderSet}} match the return value from the script.  
However, looking at log4j2 debug output, this does not appear to be working:
{noformat}
ERROR StatusLogger AppenderSet contains an invalid element or attribute 
"SyslogAppender"
D
ERROR StatusLogger No node named WindowsAppender in 
org.apache.logging.log4j.core.appender.AppenderSet@2d52216b{noformat}
So... how is this supposed to work?  A proper (and full) example that actually 
works would be kinda useful.

My hunch is that there's a disconnect related to the "strict" versus "loose" 
versions of the schema which, for all its good intentions, is just adding 
unnecessary complexity to learning log4j2 and example sharing.

 

 


was (Author: [email protected]):
The documentation for ScriptAppenderSelector is still wrong on the website.  It 
leaves a LOT to be desired.  Even the corrected documentation in these comments 
doesn't seem to work right.  The relationship between the return value from the 
script and the Appenders in the AppenderSet is confusing and almost totally 
undocumented.  For example, I have this:
{code:xml}
<ScriptAppenderSelector name="ArchDependentAppender">
        <Script language="JavaScript">
                <![CDATA[
                        try{
                                load("nashorn:mozilla_compat.js");
                        } catch(e) {}
                        importPackage(java.lang);
                        System.getProperty("os.name").search("Windows") > -1 ? 
"WindowsAppender" : "UnixAppender";
                ]]>
        </Script>
        <AppenderSet>
                <FileAppender name="WindowsAppender">
                        <PatternLayout>
                                <Pattern>${appenderPatternLayout}</Pattern>
                        </PatternLayout>
                </FileAppender>
                <SyslogAppender name="UnixAppender" 
                                                advertise="true" 
                                                facility="LOCAL1" 
                                                format="RFC5424" 
                                                host="localhost" 
                                                port="514" 
                                                protocol="TCP" 
                                                newLine="true" />
        </AppenderSet>
</ScriptAppenderSelector>
{code}
 Which, from what I can tell, *should* work because the names of the Appender 
in the AppenderSet match the return value from the script.  However, looking at 
log4j2 debug output, this does not appear to be working:
{noformat}
ERROR StatusLogger AppenderSet contains an invalid element or attribute 
"SyslogAppender"
D
ERROR StatusLogger No node named WindowsAppender in 
org.apache.logging.log4j.core.appender.AppenderSet@2d52216b{noformat}
So... how is this supposed to work?  A proper (and full) example that actually 
works would be kinda useful.

 

 

 

> Add support for properties selectors
> ------------------------------------
>
>                 Key: LOG4J2-1686
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1686
>             Project: Log4j 2
>          Issue Type: New Feature
>          Components: Configurators
>    Affects Versions: 2.7
>            Reporter: Raman Gupta
>            Assignee: Ralph Goers
>            Priority: Major
>
> It would be great to support conditional configuration like logback:
> http://logback.qos.ch/manual/configuration.html#conditional
> This allows for more advanced configuration than is currently possible with 
> property substitution.
> Example use case: to implement 
> https://issues.apache.org/jira/browse/LOG4J2-1685 without log4j library 
> support.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to