What you can also do (without Log4j enhancements) is create a plugin appender 
that takes two Appender-Refs and delegates to the correct one for your 
application. 

In configuration this could look like this:

<Appenders>
  <FileAppender name="unix" ...
  <FileAppender name="OS390" ...

  <MyDelegatingAppender name="delegator">
    <AppenderRef ref="unix" />
    <AppenderRef ref="OS390" />
  </MyDelegatingAppender>

 Remko

Sent from my iPhone

> On 2016/09/11, at 3:48, Ralph Goers <[email protected]> wrote:
> 
> Oops. I forgot the closing CDATA tag in the script.
> 
> Ralph
> 
>> On Sep 10, 2016, at 11:43 AM, Ralph Goers <[email protected]> wrote:
>> 
>> Interesting. OS/390.  I worked on MVS, OS/370, z/OS, etc many moons ago but 
>> haven’t worked on a mainframe since 2001.
>> 
>> This sort of sounds like you want an Appender Selector, which would be an 
>> Appender that uses a Selector to figure out which Appender to delegate to. 
>> This is a bit like the PatternSelector. I would imagine it would make sense 
>> to implement AppenderSelectors and LayoutSelectors.  You probably would want 
>> to dynamically initialize the Appenders much like the RoutingAppender does. 
>> 
>> Maybe it would look like:
>> 
>> <Appenders>
>>   <ScriptSelector name=“" default=“”>
>>      <Script language=“groovy”><![CDATA[
>>          if (System.getProperty”os.name”).contains(“OS/390”)) then {
>>              return “Socket”;
>>          } else {
>>              return “File”;
>>          }           
>>      </Script>
>>      <Appenders>
>>          <SocketAppender name=“Socket” …/>
>>          <FileAppender name=“File” …/>
>>      </Appenders>     
>>   </ScriptSelector>
>> </Appenders>
>> 
>> The thing is that this script would run every time the Selector was accessed 
>> while it sounds like you would only want the script to run when the Selector 
>> is initialized. We could do that too but the script would need to be 
>> declared in a property that would only be used when the selector is 
>> initialized. I would want to support being able to do both.
>> 
>> Ralph
>> 
>>> On Sep 10, 2016, at 11:04 AM, Gary Gregory <[email protected]> wrote:
>>> 
>>> <Appenders>
>>>    <ScriptTest language="JavaScript">
>>>       <If>System.getProperty("os.name").contains("OS/390")</If>
>>>       <True>
>>>          <SocketAppender ...>
>>>      </True>
>>>      <False>
>>>          <FileAppender ...>
>>>      </False>
>>>    </ScriptTest>
>>> </Appenders>
>>> 
>>> ?
>>> 
>>> 
>>>> On Sat, Sep 10, 2016 at 10:40 AM, Gary Gregory <[email protected]> 
>>>> wrote:
>>>> OK, I found 
>>>> https://logging.apache.org/log4j/2.x/manual/configuration.html#Scripts and 
>>>> I think I could use either:
>>>> 
>>>> - Use composite configurations: One file for OS/390, one for all other 
>>>> OSs; or
>>>> - Do it all in one configuration file (that seems simpler)
>>>> 
>>>> It seems like there are some pieces missing to do what I want conveniently.
>>>> 
>>>> Should I define all appenders in <Appenders> and later use a script to 
>>>> only add the one(s) I want in the <Root> section?
>>>> 
>>>> Or, should the <Appenders> section itself be scripted to only add the 
>>>> appenders I want? 
>>>> 
>>>> Since I expect the OS/390 appender will likely blow up running on a 
>>>> different OK I do not want to create it unless I know it can run OK. 
>>>> 
>>>> I guess then I have a conditional section in both the Appenders and in the 
>>>> Root section so that when I say <AppenderRef =...> we do not go look for 
>>>> an appender that is not defined.
>>>> 
>>>> Thoughts?
>>>> 
>>>> A narrow solution would be to add an "os" attribute to all appenders but 
>>>> that seems lame. os="OS/390" and os="!OS/390" means also knowing about 
>>>> "not", yikes.
>>>> 
>>>> Gary
>>>> 
>>>> On Sat, Sep 10, 2016 at 10:05 AM, Gary Gregory <[email protected]> 
>>>> wrote:
>>>>> Hi,
>>>>> 
>>>>> I can't seem to find on our site the scripting support that was recently 
>>>>> added (or is that only in master?).
>>>>> 
>>>>> What I need to do is only add a specific appender when running on a 
>>>>> specific OS (USS on OS/390 if you must know). Then only add a different 
>>>>> appender when not running on that OS.
>>>>> 
>>>>> I'd rather not have to hard-code this and make thing more complicated.
>>>>> 
>>>>> Thoughts?
>>>>> 
>>>>> Gary
>>>>> 
>>>>> -- 
>>>>> E-Mail: [email protected] | [email protected] 
>>>>> Java Persistence with Hibernate, Second Edition
>>>>> JUnit in Action, Second Edition
>>>>> Spring Batch in Action
>>>>> Blog: http://garygregory.wordpress.com 
>>>>> Home: http://garygregory.com/
>>>>> Tweet! http://twitter.com/GaryGregory
>>>> 
>>>> 
>>>> 
>>>> -- 
>>>> E-Mail: [email protected] | [email protected] 
>>>> Java Persistence with Hibernate, Second Edition
>>>> JUnit in Action, Second Edition
>>>> Spring Batch in Action
>>>> Blog: http://garygregory.wordpress.com 
>>>> Home: http://garygregory.com/
>>>> Tweet! http://twitter.com/GaryGregory
>>> 
>>> 
>>> 
>>> -- 
>>> E-Mail: [email protected] | [email protected] 
>>> Java Persistence with Hibernate, Second Edition
>>> JUnit in Action, Second Edition
>>> Spring Batch in Action
>>> Blog: http://garygregory.wordpress.com 
>>> Home: http://garygregory.com/
>>> Tweet! http://twitter.com/GaryGregory
> 

Reply via email to