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 8350C200B82 for ; Fri, 16 Sep 2016 20:43:31 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 81DC7160AC4; Fri, 16 Sep 2016 18:43:31 +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 7E2C1160AB7 for ; Fri, 16 Sep 2016 20:43:29 +0200 (CEST) Received: (qmail 26441 invoked by uid 500); 16 Sep 2016 18:43:28 -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 26424 invoked by uid 99); 16 Sep 2016 18:43:28 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 16 Sep 2016 18:43:28 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 1025D1A5465 for ; Fri, 16 Sep 2016 18:43:28 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 4.178 X-Spam-Level: **** X-Spam-Status: No, score=4.178 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HTML_MESSAGE=2, MANY_SPAN_IN_TEXT=2.999, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd2-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx2-lw-us.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id 5eqCONQphbyo for ; Fri, 16 Sep 2016 18:43:23 +0000 (UTC) Received: from mail-oi0-f51.google.com (mail-oi0-f51.google.com [209.85.218.51]) by mx2-lw-us.apache.org (ASF Mail Server at mx2-lw-us.apache.org) with ESMTPS id 758C75FAD8 for ; Fri, 16 Sep 2016 18:43:23 +0000 (UTC) Received: by mail-oi0-f51.google.com with SMTP id q188so122108694oia.3 for ; Fri, 16 Sep 2016 11:43:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=XbVeLYvixxYYD1hlCn1zA6TlFDNTBKatLfR+hZ7b3Qk=; b=EG63lkYv4PyDkCwpykLN2x+i67bizh0o2bqHVI9qkCUBg6qaY4JKpKkc6iZJbGrtoO D7QCUtpbyhBrTpgo6LIBzP5MmXnlnO8lph/umEwGAgJ4isd3E17XxLM+FQTC3tXSFb2y mL3CQFW852JnEJH2CySiU9CZn+UClryuXOxJepzBY2JJrBIqg94+ZWYbx7+wr+ctD39g i6bTR1Zrcp1scx47qUP2sjpj98Bu7M8azjiSJc6n8ZznymRRcaAIvkJZhmARpIPKkekI o6jLgdohV+2ciXaiDdr6z0k/tJpz2nIhmM2DvNrjI9aTlf82S7txBGI2gZjXbaVIvfjj vNVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=XbVeLYvixxYYD1hlCn1zA6TlFDNTBKatLfR+hZ7b3Qk=; b=Fdb1dnu5QDyqPRD1D7ctc/0dBTCAf6D1Y9qoyyWFlGm+MZIB8z79nGfe1K7rv5XSKX eq/PV6TW+DUd4RyEt9PjOnvo1NRmYlJaUomIyXnacbgcdAMxjqyLboVxlpLNx+XWrXx4 3UC1Bk5ckuP9hJuBv3dOFiSvhd+MD3sqOjhVwVPE+5ANmaUpEEyIAI4hmuKU9jK7tX80 NQnwA2FWXbBQn2ulvviv/9P6fzsKQdH2LuyrLDvNUgT6dXK81gi+EPAxS0XE+vIi1jY1 XWTRaYejMUTFOQmC5TXgGIBx3UkijnKD+UtsdaDPMBC6MngMUJb0Q2OxZSRJb+modHPm FAcQ== X-Gm-Message-State: AE9vXwMBVChCN3+sKgf/yEXPjHuaX9CqhXiLJM7p68urmv9Wz33CY4fIz3aHYqPJ+fW30HnHuhVUaMiXgzEXpg== X-Received: by 10.157.45.134 with SMTP id g6mr4659829otb.88.1474051402570; Fri, 16 Sep 2016 11:43:22 -0700 (PDT) MIME-Version: 1.0 Received: by 10.157.14.76 with HTTP; Fri, 16 Sep 2016 11:43:21 -0700 (PDT) In-Reply-To: References: <1E11A584-4C6F-43EC-9ADA-64611AC68641@dslextreme.com> <9C614807-A40E-4DE7-B38D-9D3D839E17AB@dslextreme.com> <9FEC89CA-E148-4FA5-907F-49CD8A696516@dslextreme.com> From: Gary Gregory Date: Fri, 16 Sep 2016 11:43:21 -0700 Message-ID: Subject: Re: OS-based dynamic configuration file To: Log4J Developers List Content-Type: multipart/alternative; boundary=94eb2c03231e3b248d053ca456ba archived-at: Fri, 16 Sep 2016 18:43:31 -0000 --94eb2c03231e3b248d053ca456ba Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Now I've dived into this part of the code and consider what this configuration means for my use case, I see that it works and that the new feature has merit on its own but... It feels to me like my specific use case is an edge case of this new routing appender feature: I will only ever have one route and that route is determined at start up time and will never change. So it feels rather a heavy hammer for my fly. What I think would be nicer is this: The script AddAppender runs when Appenders is instantiated and picks which appender to add. I think this means that the Appenders plugin must have deferChildren=3Dtrue= . When created the Appender checks the name of the script, right now there is only "AddAppender" but you could imagine other names like "AddAppenders" (plural). If there is no script, the Appenders plugin converts the nodes into configurations, which gives us the same result as before this change, it's just that the convertion from nodes to configured items happens a little later. If there is a script, then it is run and the semantics are applied, in my case, pick the one Appender node and convert it to a configured appender. Thoughts? Gary On Tue, Sep 13, 2016 at 4:53 PM, Gary Gregory wrote: > I committed a first cut, see comments in https://issues.apache.org/ > jira/browse/LOG4J2-1578 > > Gary > > On Mon, Sep 12, 2016 at 11:40 PM, Ralph Goers > wrote: > >> Yes, it returns the key. Remember, a Route can dynamically create an >> Appender so it isn=E2=80=99t required to be a reference. At the same ti= me we can >> (and probably should) pass variables and/or a Map to the script that it = can >> update in any way it wants for later usage by the Routing script. As is >> shown, it can also return null which leaves the default route in place. = So >> it need not be strictly for returning the default route. >> >> Ralph >> >> On Sep 12, 2016, at 10:30 PM, Gary Gregory >> wrote: >> >> Wait a sec, the DefaultRouteScript should return the Route key, not the >> Route ref. Right? >> >> Gary >> >> On Mon, Sep 12, 2016 at 9:53 PM, Gary Gregory >> wrote: >> >>> "First, the init script changes the default route based on the OS." >>> >>> Maybe the tag should be called "DefaultRouteScript" since it's job is t= o >>> return the default route name? >>> >>> Gary >>> >>> On Mon, Sep 12, 2016 at 8:05 PM, Ralph Goers >> > wrote: >>> >>>> After reviewing what I wrote below and looking at the Routing Appender >>>> I think the best thing to do is just to add script support to it. It >>>> already has support for a default Route. The init script, if present, = could >>>> override which Route to use as I described below. Then we could add a >>>> script attribute to the Routes plugin which could be used to select th= e >>>> Route instead of only matching on the ThreadContext key. >>>> >>>> With that I think you would have everything you want, plus it could be >>>> used as a more intelligent way to route to existing appenders. >>>> >>>> The configuration would then look like: >>>> >>>> >>>> >>>> >>>> >>>> >>>> >>>> >>>> >>>> >>>> >>>> ") { return =E2=80=9COS390"; } = return null;]]> >>>> >>>> >>>> >>>> >>>> >>>> >>>> >>> filePattern=3D"${mdc:UserId}.%i.log.gz"> >>>> >>>> %d %p %c{1.} [%t] %m%n >>>> >>>> >>>> >>>> >>>> >>>> >>>> >>>> >>>> >>>> >>>> >>>> First, the init script changes the default route based on the OS. >>>> Second, notice that =E2=80=9CRoutes=E2=80=9D has a new Script element = and does not have >>>> a pattern specified, so the script is determining the key instead of t= he >>>> pattern. >>>> Third, the real default route is now =E2=80=9CSTDOUT=E2=80=9D since th= e actual default >>>> Route is only referenced when a UserId is present in the thread contex= t map. >>>> >>>> What would also be nice is if there was a way to have the returned >>>> value be usable as a Lookup value in the default Appender definition, >>>> instead of relying on the MDC as the code above does. I should be able= to >>>> pick something out of the message itself and use that as the key. That >>>> should be doable but I am still pondering how I would implement that. >>>> >>>> Ralph >>>> >>>> >>>> >>>> On Sep 12, 2016, at 6:06 PM, Ralph Goers >>>> wrote: >>>> >>>> I=E2=80=99ll try to describe it better but I=E2=80=99m not sure how go= od a job I=E2=80=99ll do >>>> if the dots aren=E2=80=99t clicking yet. Also, even though I might say= to do it one >>>> way if I was coding I could very well change my mind as I implement it= . >>>> That said: >>>> >>>> 1. Create an Appender plugin named ScriptSelector or >>>> ScriptAppenderSelector. It needs the following parameters >>>> - name, a String PluginAttribute >>>> - default, a String PluginAttribute >>>> - initScript or startupScript, an AbstractScript PluginElement >>>> - script, an AbstractScript PluginElement >>>> - appenderList, an AppenderList PluginElement. >>>> 2. As always, the builder (or factory) creates an instance of the >>>> ScriptAppenderSelector. >>>> - If there is an init script then the builder (or factory) >>>> executes it. >>>> - If the returned value is not null then instantiate the >>>> Appender with that name using the configuration in the AppenderL= ist. >>>> - Whatever Appender the init script names should become the >>>> default Appender. >>>> - If no init script is present or the init script returns null >>>> use the value of the default setting as the name of the default = Appender to >>>> use. >>>> - Create the default Appender and save it in the Map of created >>>> appenders wrapped by an AppenderControl. >>>> 3. When the append method is called check for a script setting. >>>> - If a script is found, run it. >>>> - If it returns a value see if that appender is saved in the >>>> AppenderMap. >>>> - If it is, call the appender and return. >>>> - If it is not, locate the configuration for the appender, >>>> create it and add it to the AppenderMap. Then call it and ret= urn. >>>> - If it returns null or no script is defined then call the >>>> default Appender and return. >>>> 4. When the stop method is called call the stop method on each of >>>> the Appenders in the AppenderMap. >>>> >>>> >>>> Note that signatures for scripts are defined by the components that us= e >>>> them. In this case both the init script and script return the name of = the >>>> appender to execute. >>>> >>>> Ralph >>>> >>>> >>>> On Sep 12, 2016, at 12:54 PM, Gary Gregory >>>> wrote: >>>> >>>> On Sun, Sep 11, 2016 at 12:47 PM, Ralph Goers >>> com> wrote: >>>> >>>>> Yes. The Appenders tag inside the ScriptSelector are the Appenders >>>>> that are to be created. But now that I think about it, we can=E2=80= =99t use >>>>> =E2=80=9CAppenders=E2=80=9D for this. If you look at the RoutingAppen= der you will notice >>>>> that Appenders there are declared under a Route element. The Route pl= ugin >>>>> is defined with deferChildren=3Dtrue. This means that whatever is con= figured >>>>> under the Route will not be created during initial configuration. Ins= tead >>>>> the Route keeps a reference to the Node and then configures the Appen= der >>>>> when it is required. So we would need a new plugin to wrap the Append= ers >>>>> that are to be created. >>>>> >>>> >>>> Can you please describe in more detail how this new plug fits in and >>>> what it does? I can't quite connect the dots with the parallel of the >>>> routing appender. I'm willing to implement this as I need the feature = ASAP. >>>> >>>> Gary >>>> >>>> >>>>> Ralph >>>>> >>>>> On Sep 11, 2016, at 11:10 AM, Gary Gregory >>>>> wrote: >>>>> >>>>> Are the tags really meant to be nested? >>>>> >>>>> Gary >>>>> >>>>> On Sat, Sep 10, 2016 at 11:48 AM, Ralph Goers >>>> com> wrote: >>>>> >>>>>> Oops. I forgot the closing CDATA tag in the script. >>>>>> >>>>>> Ralph >>>>>> >>>>>> On Sep 10, 2016, at 11:43 AM, Ralph Goers >>>>>> wrote: >>>>>> >>>>>> Interesting. OS/390. I worked on MVS, OS/370, z/OS, etc many moons >>>>>> ago but haven=E2=80=99t 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 lik= e the >>>>>> RoutingAppender does. >>>>>> >>>>>> Maybe it would look like: >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> 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 wou= ld need >>>>>> to be declared in a property that would only be used when the select= or is >>>>>> initialized. I would want to support being able to do both. >>>>>> >>>>>> Ralph >>>>>> >>>>>> On Sep 10, 2016, at 11:04 AM, Gary Gregory >>>>>> wrote: >>>>>> >>>>>> >>>>>> >>>>>> System.getProperty("os.name").contains("OS/390") >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> ? >>>>>> >>>>>> >>>>>> On Sat, Sep 10, 2016 at 10:40 AM, Gary Gregory >>>>> m> wrote: >>>>>> >>>>>>> OK, I found https://logging.apache.org/log4j/2.x/manual/configurat >>>>>>> ion.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 and later use a script >>>>>>> to only add the one(s) I want in the section? >>>>>>> >>>>>>> Or, should the 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 we do n= ot go look >>>>>>> for an appender that is not defined. >>>>>>> >>>>>>> Thoughts? >>>>>>> >>>>>>> A narrow solution would be to add an "os" attribute to all appender= s >>>>>>> but that seems lame. os=3D"OS/390" and os=3D"!OS/390" means also kn= owing about >>>>>>> "not", yikes. >>>>>>> >>>>>>> Gary >>>>>>> >>>>>>> On Sat, Sep 10, 2016 at 10:05 AM, Gary Gregory < >>>>>>> garydgregory@gmail.com> 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 diff= erent >>>>>>>> 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: garydgregory@gmail.com | ggregory@apache.org >>>>>>>> >>>>>>>> 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: garydgregory@gmail.com | ggregory@apache.org >>>>>>> >>>>>>> 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: garydgregory@gmail.com | ggregory@apache.org >>>>>> >>>>>> 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: garydgregory@gmail.com | ggregory@apache.org >>>>> >>>>> 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: garydgregory@gmail.com | ggregory@apache.org >>>> >>>> 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: garydgregory@gmail.com | ggregory@apache.org >>> 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: garydgregory@gmail.com | ggregory@apache.org >> 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: garydgregory@gmail.com | ggregory@apache.org > 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 > --=20 E-Mail: garydgregory@gmail.com | ggregory@apache.org 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 --94eb2c03231e3b248d053ca456ba Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Now I've dived into this part of the code and consider= what this configuration means for my use case, I see that it works and tha= t the new feature has merit on its own but... It feels to me like my specif= ic use case is an edge case of this new routing appender feature: I will on= ly ever have one route and that route is determined at start up time and wi= ll never change. So it feels rather a heavy hammer for my fly.

What I think would be nicer is this:

&= lt;Configuration status=3D"WARN" name=3D"RoutingTest"&g= t;
=C2=A0 <Appenders>
=C2=A0 =C2=A0<Script nam= e=3D"AddAppender" language=3D"JavaScript"><![CDAT= A[
=C2=A0 =C2=A0 =C2=A0"OSNameFoo".search("Foo&quo= t;) > -1 ? "List2" : "List1";]]>
=C2=A0= =C2=A0</Script>
=C2=A0 =C2=A0<List name=3D"List1&q= uot; />
=C2=A0 =C2=A0<List name=3D"List2" />
=C2=A0 </Appenders>
=C2=A0 <Loggers>
=C2=A0 =C2=A0 <Root level=3D"error">
=C2=A0 = =C2=A0 =C2=A0 <AppenderRef ref=3D"Routing" />
=C2= =A0 =C2=A0 </Root>
=C2=A0 </Loggers>
</C= onfiguration>

The script AddAppender runs= when Appenders is instantiated and picks which appender to add.
=
I think this means that the Appenders plugin must have defer= Children=3Dtrue. When created the Appender checks the name of the script, r= ight now there is only "AddAppender" but you could imagine other = names like "AddAppenders" (plural). If there is no script, the Ap= penders plugin converts the nodes into configurations, which gives us the s= ame result as before this change, it's just that the convertion from no= des to configured items happens a little later. If there is a script, then = it is run and the semantics are applied, in my case, pick the one Appender = node and convert it to a configured appender.

Thou= ghts?

Gary
<= br>
On Tue, Sep 13, 2016 at 4:53 PM, Gary Gregory= <garydgregory@gmail.com> wrote:
I committed a first cut, see comments in=C2= =A0https://issues.apache.org/jira/browse/LOG4J2-1578

Gary
=

On Mon, Sep 12, 2016 at 11:40 PM, Ralph= Goers <ralph.goers@dslextreme.com> wrote:
Yes, it = returns the key. Remember, a Route can dynamically create an Appender so it= isn=E2=80=99t required to be a reference.=C2=A0 At the same time we can (a= nd probably should) pass variables and/or a Map to the script that it can u= pdate in any way it wants for later usage by the Routing script. As is show= n, it can also return null which leaves the default route in place. So it n= eed not be strictly for returning the default route.

Ralph

On Sep 12, 2016, at 10:30 PM, Gary Gregory= <garydgrego= ry@gmail.com> wrote:

Wait a sec, the= =C2=A0DefaultRouteScript should return the Route key, not the Route ref. Ri= ght?

Gary

On Mon, Sep 12, 2016 at 9:53 PM, Gary Gregory <garydgregory@gmail.com> wrote:
"First, the init script changes the d= efault route based on the OS."

Maybe the tag should be called "DefaultRouteScript" si= nce it's job is to return the default route name?

Gary
=

On Mon, Sep 12, 2016 at 8:05 PM, Ralph Goers <ralph.= goers@dslextreme.com> wrote:
After reviewing what I wrote bel= ow and looking at the Routing Appender I think the best thing to do is just= to add script support to it.=C2=A0 It already has support for a default Ro= ute. The init script, if present, could override which Route to use as I de= scribed below. Then we could add a script attribute to the Routes plugin wh= ich could be used to select the Route instead of only matching on the Threa= dContext key.

With that I think you would have eve= rything you want, plus it could be used as a more intelligent way to route = to existing appenders.

The configuration would the= n look like:

  <Appenders>
    <Console name=3D"STDOUT" target=3D"SYSTEM_OUT">
      <PatternLayout pattern=3D"%m%n"/>
    </Console>
    <Flume name=3D"AuditLogger" compress=3D"true">
      <Agent host=3D"192.168.10.101" port=3D"8800"/>
      <Agent host=3D"192.168.10.102" port=3D"8800"/>
      <RFC5424Layout enterpriseNumber=3D"18060" includeMD=
C=3D&quo=
t;true" appName=3D"MyApp"/>
    </Flume>
    <Routing name=3D?Routing?>
      <InitScript name=3D?RoutingInit" language=3D"groovy=
"><![CDATA[
         if (System.getProperty(?os.name?).contain=
s(?OS/390") {
            return =E2=80=9COS390";
         }
         return null;]]>
      </InitScript>
      <Routes>    =20
        <Script name=3D"Router" language=3D"groovy"><![CDATA[
            if (logEvent.getMarker() !=3D nul=
l && logEvent.getMarker().isInstanceOf("AUDIT")) {
                return "AUDIT";
            } else if (logEvent.getContextMap=
().containsKey("UserId")) { 
                return logEvent.getContextMap=
().get("UserId");
            }
            return "STDOUT";
            ]]>
          </Script>=20
        <Route>
=
          <OS390Appender name=3D=E2=80=9COS390-${mdc:UserId=E2=80=9D/>=
;=20
          <RollingFile name=3D"Rolling-${mdc:UserId}" fil=
eName=3D=
"${mdc:UserId}.log"
                       filePattern=3D<=
span style=3D"color:#008080">"${mdc:UserId}.%i.log.gz">
            <PatternLayout>
              <pattern>%d =
%p %c{1.} [%t] %m%n</pattern>
            </PatternLayout>
            <SizeBasedTriggeringPolicy size=3D"500" />
          </RollingFile>
        </Route>
        <Route ref=3D"AuditLogger" key=3D"Audit"=
/>
        <Route ref=3D"STDOUT" key=3D"STDOUT"/>
      </Routes>
      <IdlePurgePolicy timeToLive=3D=
"15" timeUnit=3D"minutes=
"/>
    </Routing>
  </Appenders>
First, the init script changes the default route based on the OS= .
Second, notice that =E2=80=9CRoutes=E2=80=9D has a new Script e= lement and does not have a pattern specified, so the script is determining = the key instead of the pattern.=C2=A0
Third, the real default rou= te is now =E2=80=9CSTDOUT=E2=80=9D since the actual default Route is only r= eferenced when a UserId is present in the thread context map.
What would also be nice is if there was a way to have the retur= ned value be usable as a Lookup value in the default Appender definition, i= nstead of relying on the MDC as the code above does. I should be able to pi= ck something out of the message itself and use that as the key. That should= be doable but I am still pondering how I would implement that.
=

Ralph
<= div>



O= n Sep 12, 2016, at 6:06 PM, Ralph Goers <ralph.goers@dslextreme.com> wrote:<= /div>
I=E2=80=99ll try to = describe it better but I=E2=80=99m not sure how good a job I=E2=80=99ll do = if the dots aren=E2=80=99t clicking yet. Also, even though I might say to d= o it one way if I was coding I could very well change my mind as I implemen= t it. That said:
  1. Create an Appender plugin named ScriptSe= lector or ScriptAppenderSelector. It needs the following parameters
  2. name, a String PluginAttribute
  3. default, a String PluginAttribu= te
  4. initScript or startupScript, an AbstractScript PluginElement
  5. script, an AbstractScript PluginElement
  6. appenderList, an Appen= derList PluginElement.
  7. As always, the builder (or factory) cre= ates an instance of the ScriptAppenderSelector.=C2=A0
    • If there = is an init script then the builder (or factory) executes it.=C2=A0
    • = If the returned value is not null then instantiate the Appender with that n= ame using the configuration in the AppenderList.=C2=A0
    • Whatever App= ender the init script names should become the default Appender.
    • If = no init script is present or the init script returns null use the value of = the default setting as the name of the default Appender to use.
    • Cre= ate the default Appender and save it in the Map of created appenders wrappe= d by an AppenderControl.
  8. When the append method is called chec= k for a script setting.
    • If a script is found, run it.=C2=A0
    • If it returns a value see if that appender is saved in the AppenderMap= .=C2=A0
      • If it is, call the appender and return.
      • If it i= s not, locate the configuration for the appender, create it and add it to t= he AppenderMap. Then call it and return.
    • If it returns null or= no script is defined then call the default Appender and return.
    <= li>When the stop method is called call the stop method on each of the Appen= ders in the AppenderMap.

Note that signa= tures for scripts are defined by the components that use them. In this case= both the init script and script return the name of the appender to execute= .=C2=A0

Ralph


On Sep 12, 2016, at 12:54 PM, Gary Gregory <garydgregory@gmail.= com> wrote:

O= n Sun, Sep 11, 2016 at 12:47 PM, Ralph Goers=C2=A0<r= alph.goers@dslextreme.com>=C2=A0wrote:
<= blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-l= eft-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;pa= dding-left:1ex">
Yes. The Appenders= tag inside the ScriptSelector are the Appenders that are to be created. Bu= t now that I think about it, we can=E2=80=99t use =E2=80=9CAppenders=E2=80= =9D for this. If you look at the RoutingAppender you will notice that Appen= ders there are declared under a Route element. The Route plugin is defined = with deferChildren=3Dtrue. This means that whatever is configured under the= Route will not be created during initial configuration. Instead the Route = keeps a reference to the Node and then configures the Appender when it is r= equired. So we would need a new plugin to wrap the Appenders that are to be= created.

Can you please descri= be in more detail how this new plug fits in and what it does? I can't q= uite connect the dots with the parallel of the routing appender. I'm wi= lling to implement this as I need the feature ASAP.=C2=A0

Gary


Ralph

On Sep 11, 201= 6, at 11:10 AM, Gary Gregory <garydgregory@gmail.com> wrote:

Are the=C2=A0<Appenders>= tags really meant to be nested?

Gary
<= /div>

On Sat, Sep = 10, 2016 at 11:48 AM, Ralph Goers=C2=A0<<= a href=3D"mailto:ralph.goers@dslextreme.com" target=3D"_blank">ralph.goers@= dslextreme.com>=C2=A0wrote:
Oops. I forgot the closing CD= ATA tag in the script.

Ralph

On Sep 10, 2016, at 11:43 AM, Ralph Goers <ralph.goers@dslextreme.com> wr= ote:

Interesting. OS= /390.=C2=A0 I worked on MVS, OS/370, z/OS, etc many moons ago but haven=E2= =80=99t worked on a mainframe since 2001.

This sor= t 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 imple= ment AppenderSelectors and LayoutSelectors.=C2=A0 You probably would want t= o dynamically initialize the Appenders much like the RoutingAppender does.= =C2=A0

Maybe it would look like:

<Appenders>
=C2=A0=C2=A0<ScriptSele= ctor name=3D=E2=80=9C" default=3D=E2=80=9C=E2=80=9D>
=C2= =A0 =C2=A0 =C2=A0<Script language=3D=E2=80=9Cgroovy=E2=80=9D><![CD= ATA[
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (System.getProperty=E2= =80=9Dos.name=E2=80=9D).<= wbr>contains(=E2=80=9COS/390=E2=80=9D)) then {
=C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return =E2=80=9CSocket=E2=80=9D;
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0} else {
=C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0return =E2=80=9CFile=E2=80=9D;
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0} =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=A0
=
=C2=A0 =C2=A0 =C2=A0</Script>
=C2=A0 =C2=A0 =C2=A0<= Appenders>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0<SocketAppende= r name=3D=E2=80=9CSocket=E2=80=9D =E2=80=A6/>
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0<FileAppender name=3D=E2=80=9CFile=E2=80=9D =E2=80= =A6/>
=C2=A0 =C2=A0 =C2=A0</Appenders> =C2=A0 =C2=A0=C2= =A0
=C2=A0=C2=A0</ScriptSelector>
&l= t;/Appenders>

The thing is that this script wou= ld 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 t= hat too but the script would need to be declared in a property that would o= nly 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 <garydgregory@gmail.com= > wrote:

<Appenders>
=C2=A0= =C2=A0<ScriptTest language=3D"JavaScript">
=C2= =A0 =C2=A0 =C2=A0=C2=A0<If>System.getProperty("os.name").contains(= "OS/390")</If>
=C2=A0 =C2=A0 =C2=A0=C2=A0<True>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0<SocketApp= ender ...>
=C2=A0 =C2=A0 =C2=A0</True>
=C2=A0 = =C2=A0 =C2=A0<False>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0<= FileAppender ...>
=C2=A0 =C2=A0 =C2=A0</False>
=C2=A0 =C2=A0</ScriptTest>
</Appenders>

?

On Sat, Sep 10, 2016 at 10:40 AM, Gary Gregory<= span>=C2=A0<garydgregory@gmail.com>= =C2=A0wrote:
OK, I found=C2=A0<= a href=3D"https://logging.apache.org/log4j/2.x/manual/configuration.html#Sc= ripts" target=3D"_blank">https://logging.apache.org/log4j/2.x/manual/c= onfiguration.html#Scripts=C2=A0and I think I could us= e either:

- Use composite configurations: One file for O= S/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 scrip= t to only add the one(s) I want in the <Root> section?

=
Or, should the <Appenders> section itself be scripted to o= nly add the appenders I want?=C2=A0

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.=C2=A0

<= div>I guess then I have a conditional section in both the Appenders and in = the Root section so that when I say <AppenderRef =3D...> we do not go= look for an appender that is not defined.

Thought= s?

A narrow solution would be to add an "os&q= uot; attribute to all appenders but that seems lame. os=3D"OS/390"= ; and os=3D"!OS/390" means also knowing about "not", yi= kes.

Gary

On Sat, Sep 10, 2016 at 10:05 AM, Gary Gregory=C2=A0<garydgregory@gmail.com>=C2=A0wrote:
Hi,

I can't seem = to find on our site the scripting support that was recently added (or is th= at 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 mu= st 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?



<= br>
--=C2=A0


<= br>
--=C2=A0








--=C2=A0
=




--



--
=



--



--
= --94eb2c03231e3b248d053ca456ba--