Customising access logs in spring-boot - undertow

185 Views Asked by At

I have undertow properties configured in spring-boot - application.yaml as below:

undertow:
    accesslog:
      dir: logs/access
      enabled: true
      pattern: '%h %l %u %t "%r" %s %b %D'

I want set custom value to one of the attribute in pattern, say for %u I want to log modified value for user, how can I achieve that? I have current code in-progress as below:

@Component
public class UndertowAccessLogHandler implements WebServerFactoryCustomizer<ConfigurableUndertowWebServerFactory> {

    private final ServerProperties serverProperties;

    public UndertowAccessLogHandler(ServerProperties serverProperties) {
        this.serverProperties = serverProperties;
    }

    @Override
    public void customize(ConfigurableUndertowWebServerFactory factory) {
        String pattern = serverProperties.getUndertow().getAccesslog().getPattern();
        factory.setAccessLogPattern(pattern.replace("%u", "sample_user"));
    }
}

How can I achieve the expected result in more systematic way?

0

There are 0 best solutions below