I have undertow properties configured in 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?
Comment From: wilkinsona
The pattern is passed straight into Undertow so you can configure whatever Undertow allows you to configure. If you want to replace the user with a hardcoded sample_user as your code is doing, you can configure that in the pattern:
pattern: '%h %l sample_user %t "%r" %s %b %D'
If you have any further questions, please follow up on Stack Overflow or Gitter. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements.