logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Remko Popma <remko.po...@gmail.com>
Subject Re: Log4j2 script to generate hash
Date Wed, 09 Nov 2016 00:21:38 GMT
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 <benjamin.jaton@gmail.com> 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(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 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 <boards@gmail.com> 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 <boards@gmail.com>
>>>> 
>> 
>> ---------------------------------------------------------------------
>> 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


Mime
View raw message