Skip to content

Commit

Permalink
Get rid of JUL from everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-v committed Oct 6, 2024
1 parent c2a8805 commit 19aa382
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

import com.bettercloud.vault.VaultConfig;
import com.bettercloud.vault.VaultException;
import java.lang.System.Logger;
import java.lang.System.Logger.Level;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;
import java.util.logging.Logger;

public class VaultClientTokenSupplier {

private static final Logger LOGGER = Logger.getLogger(VaultClientTokenSupplier.class.getName());
private static final Logger LOGGER = System.getLogger(VaultClientTokenSupplier.class.getName());

private final String vaultAddress;
private final String vaultToken;
Expand Down Expand Up @@ -73,7 +74,8 @@ private String getToken0() {

if (!isNullOrNoneOrEmpty(vaultRole)) {
if (!isNullOrNoneOrEmpty(vaultToken)) {
LOGGER.warning(
LOGGER.log(
Level.WARNING,
"Taking KubernetesVaultTokenSupplier by precedence rule, "
+ "ignoring EnvironmentVaultTokenSupplier "
+ "(specify either vaultToken or vaultRole, not both)");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import io.scalecube.config.ConfigSourceNotAvailableException;
import io.scalecube.config.source.ConfigSource;
import io.scalecube.config.source.LoadedConfigProperty;
import java.lang.System.Logger;
import java.lang.System.Logger.Level;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand All @@ -19,8 +21,6 @@
import java.util.Set;
import java.util.function.Function;
import java.util.function.UnaryOperator;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;

/**
Expand All @@ -30,7 +30,7 @@
*/
public class VaultConfigSource implements ConfigSource {

private static final Logger LOGGER = Logger.getLogger(VaultConfigSource.class.getName());
private static final Logger LOGGER = System.getLogger(VaultConfigSource.class.getName());

private static final EnvironmentLoader ENVIRONMENT_LOADER = new EnvironmentLoader();

Expand Down Expand Up @@ -58,12 +58,12 @@ public Map<String, ConfigProperty> loadConfig() {
result.putAll(pathProps);
} catch (VaultException ex) {
if (ex.getHttpStatusCode() == 404) {
LOGGER.log(Level.SEVERE, "Unable to load config properties from: " + path);
LOGGER.log(Level.ERROR, "Unable to load config properties from: " + path);
} else {
throw new ConfigSourceNotAvailableException(ex);
}
} catch (Exception ex) {
LOGGER.log(Level.SEVERE, "Unable to load config properties from: " + path, ex);
LOGGER.log(Level.ERROR, "Unable to load config properties from: " + path, ex);
throw new ConfigSourceNotAvailableException(ex);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import com.bettercloud.vault.response.VaultResponse;
import com.bettercloud.vault.rest.RestResponse;
import io.scalecube.config.utils.ThrowableUtil;
import java.lang.System.Logger;
import java.lang.System.Logger.Level;
import java.nio.charset.StandardCharsets;
import java.util.Objects;
import java.util.Optional;
Expand All @@ -17,12 +19,10 @@
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.function.UnaryOperator;
import java.util.logging.Level;
import java.util.logging.Logger;

public class VaultInvoker {

private static final Logger LOGGER = Logger.getLogger(VaultInvoker.class.getName());
private static final Logger LOGGER = System.getLogger(VaultInvoker.class.getName());

private static final int STATUS_CODE_FORBIDDEN = 403;
public static final int STATUS_CODE_HEALTH_OK = 200;
Expand Down Expand Up @@ -64,7 +64,8 @@ public <T extends VaultResponse> T invoke(VaultCall<T> call) throws VaultExcepti
if (e.getHttpStatusCode() == STATUS_CODE_FORBIDDEN) {
LOGGER.log(
Level.WARNING,
String.format("Authentication failed: %s, now trying to recreate vault", e));
"Authentication failed (error message: {0}), now trying to recreate vault",
e.getMessage());
vault = recreateVault(vault);
return call.apply(vault);
}
Expand Down Expand Up @@ -101,11 +102,11 @@ private synchronized Vault recreateVault(Vault prev) throws VaultException {
Level.INFO,
String.format("Renew token timer was set to %ssec, (TTL = %ssec)", delay, ttl));
} else {
LOGGER.warning("Vault token is not renewable");
LOGGER.log(Level.WARNING, "Vault token is not renewable");
}
this.vault = vault;
} catch (VaultException e) {
LOGGER.log(Level.SEVERE, "Could not initialize and validate the vault", e);
LOGGER.log(Level.ERROR, "Could not initialize and validate the vault", e);
throw e;
}
return vault;
Expand All @@ -119,9 +120,8 @@ private void renewToken() throws VaultException {
try {
AuthResponse response = vault.auth().renewSelf();
long ttl = response.getAuthLeaseDuration();
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(
Level.FINE, String.format("Token was successfully renewed (new TTL = %ssec)", ttl));
if (LOGGER.isLoggable(Level.DEBUG)) {
LOGGER.log(Level.DEBUG, "Token was successfully renewed (new TTL = {0}sec)", ttl);
}
if (response.isAuthRenewable()) {
if (ttl > 1) {
Expand All @@ -133,7 +133,7 @@ private void renewToken() throws VaultException {
vault = recreateVault(vault);
}
} else {
LOGGER.warning("Vault token is not renewable now");
LOGGER.log(Level.WARNING, "Vault token is not renewable now");
}
} catch (VaultException e) {
// try recreate Vault according to https://www.vaultproject.io/api/overview#http-status-codes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package io.scalecube.config.vault;

import java.lang.System.Logger;
import java.lang.System.Logger.Level;
import java.util.Map;
import java.util.Objects;
import java.util.logging.Logger;

public class VaultInvokers {

public static final Logger LOGGER = Logger.getLogger(VaultInvokers.class.getName());
public static final Logger LOGGER = System.getLogger(VaultInvokers.class.getName());

public static final String VAULT_MOUNT_POINT_ENV = "VAULT_MOUNT_POINT";
public static final String VAULT_ADDR_ENV = "VAULT_ADDR";
Expand Down Expand Up @@ -65,7 +66,8 @@ public static VaultInvoker newVaultInvoker() {

if (!isNullOrNone(vaultRole)) {
if (!isNullOrNone(vaultToken)) {
LOGGER.warning(
LOGGER.log(
Level.WARNING,
"Taking KubernetesVaultTokenSupplier by precedence rule, "
+ "ignoring EnvironmentVaultTokenSupplier "
+ "(specify either VAULT_ROLE or VAULT_TOKEN, not both)");
Expand Down

0 comments on commit 19aa382

Please sign in to comment.