Search code examples
loggingfilterwildflyhandlerwildfly-10

Using Multiple filter-spec in Wildfly Logger


I'm using Wildfly 10 and I want store server log in a json file with some filters, here is my log:

{
    "msg": "\n[\"getDataMethod\" req. received]\n[password: ***]\n[prop2: value2]]\n",
    "field1": "value1"
}{
    "msg": "\n[call \"getDataMethod\"]\n[password: ***]\n[prop2: value2]]\n",
    "field2": "value2"
}{
    "msg": "full-XML SOAP request",
    "field3": "value3"
}{
    "msg": "\n[\"getDataMethod\" finished...]\n[password: ***]\n[prop2: value2]]\n",
    "field4": "value4"
}

But this log file has two problems:

  1. the msg field contains critical information (like password) and I want filter them.
  2. some of information is redundant and I don't want store them. (for example, nodes contains "req. received" or "call getDataMethod")

for solving problem #1, I write this filter-spec and remove all bucket with regex:

<logger category="org.somePackags.MyClass" use-parent-handlers="false">
    <level name="INFO" />
    <filter-spec value="all(match(&quot;\\[(.*)\\]&quot;),substituteAll(&quot;\\[(.*)\\]&quot;, &quot; &quot;))" />
    <handlers>
        <handler name="JsonLog" />
    </handlers>
</logger>

Now I want add rules to filter-spec to exclude nodes that match in problem #2, I read FilterExpressions, But I don't know how to write Multiple filter-spec. any idea?


Solution

  • The all filter will process each filter in the chain and if any of the filters in the chain deem the message unloggable, then the message isn't logged. The all with the substituteAll filter does seem to be the one you should be using. You'd just add more substituteAll filters in the chain.

    What you'd need to figure out is the patterns to replace the data. You could remove the match as well it looks like it's just matching everything anyway.