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 C30F2200BBB for ; Thu, 10 Nov 2016 23:15:34 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id C1AE6160B01; Thu, 10 Nov 2016 22:15:34 +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 E0C3F160AF7 for ; Thu, 10 Nov 2016 23:15:33 +0100 (CET) Received: (qmail 42972 invoked by uid 500); 10 Nov 2016 22:15:32 -0000 Mailing-List: contact log4j-user-help@logging.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Log4J Users List" Reply-To: "Log4J Users List" Delivered-To: mailing list log4j-user@logging.apache.org Received: (qmail 42961 invoked by uid 99); 10 Nov 2016 22:15:32 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 Nov 2016 22:15:32 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 6DF731812D7 for ; Thu, 10 Nov 2016 22:15:32 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 2.379 X-Spam-Level: ** X-Spam-Status: No, score=2.379 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HTML_MESSAGE=2, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RCVD_IN_SORBS_SPAM=0.5, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd3-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id wZxfTMoY-6aq for ; Thu, 10 Nov 2016 22:15:29 +0000 (UTC) Received: from mail-lf0-f53.google.com (mail-lf0-f53.google.com [209.85.215.53]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTPS id E86185F65A for ; Thu, 10 Nov 2016 22:15:28 +0000 (UTC) Received: by mail-lf0-f53.google.com with SMTP id t196so201568716lff.3 for ; Thu, 10 Nov 2016 14:15:28 -0800 (PST) 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=SNOTv5k/6mH/CzGcCqZONheH8GsRBRYkcNWveiw8bec=; b=RjIPAzOQ4JoQZAbBcxOyqyBEpStgWLbh4i4jFKsn+KAJKGWXfizEbCexmX11ZiQF8p 3oWOP3ecNT0xu64CwCLR95JoVVkw3PGmumVkBSEBe33ZukqYsB8u+E/xZpMMDSGJjbtI tjqtGHk5u0/jbyVkQkmNZAN4JUEHJPgg3o7F3nB5YMC0sT4Z5K89rBN0eVRnwgMNBcPg rtXuL2zulqRSCnEjUYWS6nzPpOMIpcQYUjreYNYLUMS3b91Q5C2SOPPPmtoNwM6fF7IH U183g5PkhVM7eY6q5wMg4t5XHyFe+7/Op+FGJDjx/LEBrOXF42MV0AKefxLM6OmxalTM 5i7w== 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=SNOTv5k/6mH/CzGcCqZONheH8GsRBRYkcNWveiw8bec=; b=LK1rAyA/6yw216MxU1+D6robZdfH//BZ6OhsbqNK+jOZdZfH/30OZxUxICqs1Jj1Rz YK/tz8m8fd+JTkou7CU/ig3naby3+4Nc8Dm09VzIMzvfVw/Pyo6MKm2fkxT8djnPAirs WSUpElquVPSUL0efQmcWhOjCPfHW3RzsMTM9ua4XUSwpgy0ruGZs3DGt9l02IGZrMFFb 9MMAjZHdGRIllgEFswZ6fj0hD1rVsNmMO1U4ykcRfaIyMs14r3TyuhAEAy6bP07HmqJq omV1z/BBBJGM6PSeKbh5atErpxgjoY8qqzw/FXQLE3dtTCzIqNAEy8JN8or6ACJm6wCa hazQ== X-Gm-Message-State: ABUngvfi8mH6FKKXg9KU1ua/cC3iQcfXW6dU95vSQ+4zNL+FinQJA8HE6+Bsu9CqBAshyLV9kG5HiHBlsfhP+A== X-Received: by 10.25.19.106 with SMTP id j103mr4556321lfi.68.1478816126698; Thu, 10 Nov 2016 14:15:26 -0800 (PST) MIME-Version: 1.0 Received: by 10.25.23.210 with HTTP; Thu, 10 Nov 2016 14:15:25 -0800 (PST) In-Reply-To: <2F77DDF1-55A7-433C-B69F-FA28E704A8F7@gmail.com> References: <2F77DDF1-55A7-433C-B69F-FA28E704A8F7@gmail.com> From: Benjamin Jaton Date: Thu, 10 Nov 2016 14:15:25 -0800 Message-ID: Subject: Re: Log4j2 script to generate hash To: Log4J Users List Content-Type: multipart/alternative; boundary=001a11406ba0eb88020540f9b579 archived-at: Thu, 10 Nov 2016 22:15:34 -0000 --001a11406ba0eb88020540f9b579 Content-Type: text/plain; charset=UTF-8 Sure, here it is: { "configuration" : { "status" : "warn", "scripts": { "ScriptFile": { "name":"test.filter", "path": "/usr/local/apps/test.groovy" } }, "ScriptFilter": { "onMatch": "ACCEPT", "onMisMatch": "DENY", "ScriptRef": { "ref": "test.filter" } }, "appenders" : { "appender" : [ { "type" : "Console", "name" : "STDOUT", "PatternLayout" : { "pattern" : "%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1.}:%L - [%X{md5message}] %m%n" } } ] }, "loggers" : { "root" : { "level" : "INFO", "additivity" : "false", "includeLocation" : "true", "AppenderRef" : { "ref" : "STDOUT" } } } } } On Thu, Nov 10, 2016 at 9:01 AM, Remko Popma wrote: > Can you show your configuration? > > Sent from my iPhone > > > On 11 Nov 2016, at 1:56, Benjamin Jaton > wrote: > > > > I tried all the variables in the doc, no luck: > > > > Caused by: groovy.lang.MissingPropertyException: No such property: > > loggerName for class: Script2 > > at > > org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap( > ScriptBytecodeAdapter.java:53) > > at > > org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty( > PogoGetPropertySite.java:52) > > at > > org.codehaus.groovy.runtime.callsite.AbstractCallSite. > callGroovyObjectGetProperty(AbstractCallSite.java:307) > > at Script2.run(Script2.groovy:8) > > at > > org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval( > GroovyScriptEngineImpl.java:343) > > ... 12 more > > > >> On Wed, Nov 9, 2016 at 10:54 PM, Remko Popma > wrote: > >> > >> According to this https://logging.apache.org/ > >> log4j/2.x/manual/filters.html#Script you should be able to use the > >> variable named loggerName in global script filters. > >> > >> Sent from my iPhone > >> > >>> On 10 Nov 2016, at 4:31, Benjamin Jaton > >> wrote: > >>> > >>> Hmm, I'm not sure, I tried to do this in groovy: > >>> > >>> println(args[0]) > >>> > >>> But I get: > >>> Caused by: groovy.lang.MissingPropertyException: No such property: > args > >> for > >>> class: Script2 > >>> at > >>> org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap( > >> ScriptBytecodeAdapter.java:53) > >>> at > >>> org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty( > >> PogoGetPropertySite.java:52) > >>> at > >>> org.codehaus.groovy.runtime.callsite.AbstractCallSite. > >> callGroovyObjectGetProperty(AbstractCallSite.java:307) > >>> at Script2.run(Script2.groovy:8) > >>> at > >>> org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval( > >> GroovyScriptEngineImpl.java:343) > >>> ... 12 more > >>> > >>> Then I tried: > >>> > >>> println(parameters) > >>> > >>> But it returns 'null' > >>> > >>>> On Tue, Nov 8, 2016 at 5:18 PM, Remko Popma > >> wrote: > >>>> > >>>> All filter methods have a Logger object as the first parameter. Can > you > >>>> use that? > >>>> > >>>> Sent from my iPhone > >>>> > >>>>> On 9 Nov 2016, at 9:45, Benjamin Jaton > >> wrote: > >>>>> > >>>>> As far as I know, there is no way for a global filter to know which > >>>> logger > >>>>> we're working it for. > >>>>> Which in my case is not the best since I would compute a hash for all > >> the > >>>>> messages of all my loggers, instead of just the one I need them for. > >>>>> > >>>>> On Tue, Nov 8, 2016 at 4:30 PM, Benjamin Jaton < > >> benjamin.jaton@gmail.com > >>>>> > >>>>> wrote: > >>>>> > >>>>>> Ah, I can't use 'logEvent' but I can use 'message', perfect, thank > >> you! > >>>>>> > >>>>>>> On Tue, Nov 8, 2016 at 4:21 PM, Remko Popma > > >>>> wrote: > >>>>>>> > >>>>>>> Yes Filters can be applied at different stages of the logging > >> pipeline. > >>>>>>> The Filter interface has separate methods for these stages. > Different > >>>>>>> parameters are passed to these methods. > >>>>>>> > >>>>>>> Sent from my iPhone > >>>>>>> > >>>>>>>> On 9 Nov 2016, at 8:57, Benjamin Jaton > >>>>>>> wrote: > >>>>>>>> > >>>>>>>> Ah, interesting. I seem to be able to make modification using this > >>>>>>> global > >>>>>>>> filter. > >>>>>>>> > >>>>>>>> However I don't seem to have access to the log event that way? > >>>>>>>> > >>>>>>>> Caused by: groovy.lang.MissingPropertyException: No such > property: > >>>>>>> logEvent > >>>>>>>> for class: Script2 > >>>>>>>> at > >>>>>>>> org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(Scr > >>>>>>> iptBytecodeAdapter.java:53) > >>>>>>>> at > >>>>>>>> org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.get > >>>>>>> Property(PogoGetPropertySite.java:52) > >>>>>>>> at > >>>>>>>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGr > >>>>>>> oovyObjectGetProperty(AbstractCallSite.java:307) > >>>>>>>> at Script2.run(Script2.groovy:8) > >>>>>>>> at > >>>>>>>> org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(Groov > >>>>>>> yScriptEngineImpl.java:343) > >>>>>>>> ... 12 more > >>>>>>>> > >>>>>>>>> On Tue, Nov 8, 2016 at 3:47 PM, Remko Popma < > remko.popma@gmail.com > >>> > >>>>>>> wrote: > >>>>>>>>> > >>>>>>>>> If you make it a global filter it will get applied before the > >>>> LogEvent > >>>>>>> is > >>>>>>>>> constructed. Please try that. > >>>>>>>>> > >>>>>>>>> Remko > >>>>>>>>> > >>>>>>>>> Sent from my iPhone > >>>>>>>>> > >>>>>>>>>> On 9 Nov 2016, at 7:02, Benjamin Jaton < > benjamin.jaton@gmail.com> > >>>>>>> wrote: > >>>>>>>>>> > >>>>>>>>>> I am applying it on the root logger. > >>>>>>>>>> > >>>>>>>>>>> On Tue, Nov 8, 2016 at 12:47 PM, Matt Sicker > > >>>>>>> wrote: > >>>>>>>>>>> > >>>>>>>>>>> Where are you applying the filter? On the appender or somewhere > >>>> else? > >>>>>>>>>>> > >>>>>>>>>>> On 8 November 2016 at 13:13, Benjamin Jaton < > >>>>>>> benjamin.jaton@gmail.com> > >>>>>>>>>>> wrote: > >>>>>>>>>>> > >>>>>>>>>>>> hello, > >>>>>>>>>>>> > >>>>>>>>>>>> I was playing with log4j2 filters to generate a hash in groovy > >>>> that > >>>>>>> I > >>>>>>>>>>> would > >>>>>>>>>>>> put in the threadcontext map, and then use in my log pattern: > >>>>>>>>>>>> > >>>>>>>>>>>> %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1.}:%L - %m [%X{myhash}] > >>>>>>>>>>>> > >>>>>>>>>>>> But the hash is printed on the NEXT log message. > >>>>>>>>>>>> My understanding is that at this point the log message is > >> already > >>>>>>>>>>> formatted > >>>>>>>>>>>> and final. > >>>>>>>>>>>> > >>>>>>>>>>>> Is there another way I can use a custom script where the log > >> event > >>>>>>> can > >>>>>>>>>>>> actually be modified? > >>>>>>>>>>>> > >>>>>>>>>>>> Thanks, > >>>>>>>>>>>> Ben > >>>>>>>>>>>> > >>>>>>>>>>> > >>>>>>>>>>> > >>>>>>>>>>> > >>>>>>>>>>> -- > >>>>>>>>>>> Matt Sicker > >>>>>>>>>>> > >>>>>>>>> > >>>>>>>>> ------------------------------------------------------------ > >>>> --------- > >>>>>>>>> To unsubscribe, e-mail: log4j-user-unsubscribe@ > logging.apache.org > >>>>>>>>> For additional commands, e-mail: log4j-user-help@logging. > >> apache.org > >>>>>>>>> > >>>>>>>>> > >>>>>>> > >>>>>>> ------------------------------------------------------------ > >> --------- > >>>>>>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org > >>>>>>> For additional commands, e-mail: log4j-user-help@logging. > apache.org > >>>>>>> > >>>>>>> > >>>>>> > >>>> > >>>> --------------------------------------------------------------------- > >>>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org > >>>> For additional commands, e-mail: log4j-user-help@logging.apache.org > >>>> > >>>> > >> > > --------------------------------------------------------------------- > To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org > For additional commands, e-mail: log4j-user-help@logging.apache.org > > --001a11406ba0eb88020540f9b579--