@Test public void interceptor() throws Exception { Config config = new SmallRyeConfigBuilder() .addDefaultSources() .addDefaultInterceptors() .withSources(new ConfigValuePropertiesConfigSource( LoggingConfigSourceInterceptorTest.class.getResource("/config-values.properties"))) .withInterceptors(new LoggingConfigSourceInterceptor()) .withSecretKeys("secret") .build(); assertEquals("abc", config.getValue("my.prop", String.class)); assertThrows(SecurityException.class, () -> config.getValue("secret", String.class)); assertThrows(NoSuchElementException.class, () -> config.getValue("not.found", String.class)); assertEquals("12345678", SecretKeys.doUnlocked(() -> config.getValue("secret", String.class))); List<String> logs = logCapture.records().stream().map(LogRecord::getMessage).collect(toList()); assertTrue(logs.get(2).startsWith("SRCFG01001")); assertTrue(logs.get(2).contains("The config my.prop was loaded from ConfigValuePropertiesConfigSource")); assertTrue(logs.get(2).contains(":1 with the value abc")); assertEquals("SRCFG01002: The config not.found was not found", logs.get(3)); assertEquals("SRCFG01001: The config secret was loaded from secret with the value secret", logs.get(4)); }
@Override public ConfigValue getValue(final ConfigSourceInterceptorContext context, final String name) { try { ConfigValue configValue = doLocked(() -> context.proceed(name)); if (configValue != null) ConfigLogging.log.lookup(configValue.getName(), configValue.getLocation(), configValue.getValue()); else ConfigLogging.log.notFound(name); return configValue; } catch (SecurityException e) { } final ConfigValue secret = context.proceed(name); if (secret != null) ConfigLogging.log.lookup(secret.getName(), "secret", "secret"); else ConfigLogging.log.notFound(name); return secret; }
LoggingConfigSourceInterceptor implements ConfigSourceInterceptor { @Override public ConfigValue getValue(final ConfigSourceInterceptorContext context, final String name) { try { ConfigValue configValue = doLocked(() -> context.proceed(name)); if (configValue != null) ConfigLogging.log.lookup(configValue.getName(), configValue.getLocation(), configValue.getValue()); else ConfigLogging.log.notFound(name); return configValue; } catch (SecurityException e) { } final ConfigValue secret = context.proceed(name); if (secret != null) ConfigLogging.log.lookup(secret.getName(), "secret", "secret"); else ConfigLogging.log.notFound(name); return secret; } }
LoggingConfigSourceInterceptor implements ConfigSourceInterceptor { @Override public ConfigValue getValue(final ConfigSourceInterceptorContext context, final String name) { try { ConfigValue configValue = doLocked(() -> context.proceed(name)); if (configValue != null) ConfigLogging.log.lookup(configValue.getName(), configValue.getLocation(), configValue.getValue()); else ConfigLogging.log.notFound(name); return configValue; } catch (SecurityException e) { } final ConfigValue secret = context.proceed(name); if (secret != null) ConfigLogging.log.lookup(secret.getName(), "secret", "secret"); else ConfigLogging.log.notFound(name); return secret; }  }
LoggingConfigSourceInterceptor implements ConfigSourceInterceptor { @Override public ConfigValue getValue(final ConfigSourceInterceptorContext context, final String name) { try { ConfigValue configValue = doLocked(() -> context.proceed(name)); if (configValue != null) ConfigLogging.log.lookup(configValue.getName(), configValue.getLocation(), configValue.getValue()); else ConfigLogging.log.notFound(name); return configValue; } catch (SecurityException e) { } final ConfigValue secret = context.proceed(name); if (secret != null) ConfigLogging.log.lookup(secret.getName(), "secret", "secret"); else ConfigLogging.log.notFound(name); return secret; }  @Override ConfigValue getValue(final ConfigSourceInterceptorContext context, final String name); }
LoggingConfigSourceInterceptor implements ConfigSourceInterceptor { @Override public ConfigValue getValue(final ConfigSourceInterceptorContext context, final String name) { try { ConfigValue configValue = doLocked(() -> context.proceed(name)); if (configValue != null) ConfigLogging.log.lookup(configValue.getName(), configValue.getLocation(), configValue.getValue()); else ConfigLogging.log.notFound(name); return configValue; } catch (SecurityException e) { } final ConfigValue secret = context.proceed(name); if (secret != null) ConfigLogging.log.lookup(secret.getName(), "secret", "secret"); else ConfigLogging.log.notFound(name); return secret; }  @Override ConfigValue getValue(final ConfigSourceInterceptorContext context, final String name);  }