SAP / cf-java-logging-support

The Java Logging Support for Cloud Foundry supports the creation of structured log messages and the collection of request metrics
Apache License 2.0
77 stars 48 forks source link

Provide default Filters used in RequestLoggingFilter by static method #102

Closed KarstenSchnitter closed 3 years ago

KarstenSchnitter commented 3 years ago

When customising the RequestLoggingFilter a developer cannot get the default filters. This makes it harder to replace one of the filters with an own implementation. There should be an additional static function to retrieve the filters, e.g.:

public static Filter[] getDefaultFilters() {
    return new Filter[] {
        new AddVcapEnvironmentToLogContextFilter(),
        new AddHttpHeadersToLogContextFilter(),
        new CorrelationIdFilter(),
        new DynamicLogLevelFilter(),
        new GenerateRequestLogFilter()
    };
}

public RequestLoggingFilter() {
    super(getDefaultFilters());
}

A custom subclass of RequestLoggingFilter could use this function like this to substitute the DynamicLogLevelFilter for example:

public CustomRequestLoggingFilter() {
  super(Stream.of(getDefaultFilters())
    .map(f -> f instanceof DynamicLogLevelFilter ? new CustomDynamicLogLevelFilter() : f)
    .toArray(Filter[]::new)
  );
}