0

我想替换日志中的一些子字符串。使用具有专有日志记录的 JBOSS 6。

例如这个:

<password>myoutstandingpassword</password>

<password>xxxxxxxxxxxxxxxxxxxxx</password>

到目前为止,我可以通过使用 jboss-logging.xml 中的过滤器来过滤日志中的此类行。

<filter>
<not><match pattern="password"/></not>
</filter>

此过滤器放置在日志处理程序中。这将完全删除该行。

但是如何只删除我不知道的子字符串。找不到文档。搜索源代码相当累人。

注意:应该可以在 JBOSS AS 6 - http://www.mastertheboss.com/jboss-log/using-log4j-with-jboss-6中使用 Log4j 。在 Log4j 中,可能可以完成替换。我喜欢在没有那个的情况下实现替换。

4

1 回答 1

0

问题是我想过滤掉 org.apache.cxf.interceptor.LoggingInInterceptor 记录的一些数据。在 JBOSS AS 6 中实现日志过滤是有问题的,所以最终的解决方案是使用我自己的自定义 LoggingInInterceptor 并对其进行修改。

这样做是这样的:

我创建了一个扩展 org.apache.cxf.interceptor.LoggingInInterceptor 的类。

public class CXFLoggingInInterceptor extends LoggingInInterceptor {

    private String myCustomLogStringOperation(String logString) {

    ...

    }

    @Override
    protected String transform(String originalLogString) {
        return myCustomLogStringOperation(originalLogString);
    }

}

注意被覆盖的方法transform。在那里,您将对文本进行操作,然后将其记录下来!

然后,我向已完成日志记录的 Web 服务添加了注释。注释是@OutInterceptors,它将替换默认的拦截器。

@WebService(
    name = ....
    endpointInterface = ....
)
@InInterceptors(interceptors = package.CXFLoggingInInterceptor)
@Stateless(name = ...)
@Remote(....)
@RemoteBinding(jndiBinding = ....)
public class MyClass implements MyClassInterface

....

CXFLoggingInInterceptor 就是我们一开始定义的类。

于 2013-07-23T10:24:23.380 回答