Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align logging #204

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/java/com/bettercloud/vault/Vault.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
public class Vault {

private final VaultConfig vaultConfig;
private Logger logger = Logger.getLogger(Vault.class.getCanonicalName());
private static final Logger logger = Logger.getLogger(Vault.class.getCanonicalName());

/**
* Construct a Vault driver instance with the provided config settings.
Expand Down Expand Up @@ -282,7 +282,7 @@ private Map<String, String> collectSecretEngineVersions() {
}
return data;
} catch (RestException e) {
System.err.print(String.format("Unable to retrieve the KV Engine secrets, due to exception: %s", e.getMessage()));
logger.severe(String.format("Unable to retrieve the KV Engine secrets, due to exception: %s", e.getMessage()));
return null;
}
}
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/com/bettercloud/vault/VaultConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.Serializable;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger;

/**
* <p>A container for the configuration settings needed to initialize a <code>Vault</code> driver instance.</p>
Expand All @@ -25,6 +26,8 @@
*/
public class VaultConfig implements Serializable {

private static final Logger logger = Logger.getLogger(VaultConfig.class.getCanonicalName());

protected static final String VAULT_TOKEN = "VAULT_TOKEN";
private static final String VAULT_ADDR = "VAULT_ADDR";
private static final String VAULT_OPEN_TIMEOUT = "VAULT_OPEN_TIMEOUT";
Expand Down Expand Up @@ -327,16 +330,16 @@ public VaultConfig build() throws VaultException {
try {
this.openTimeout = Integer.valueOf(environmentLoader.loadVariable(VAULT_OPEN_TIMEOUT));
} catch (NumberFormatException e) {
System.err.printf("The " + VAULT_OPEN_TIMEOUT + " environment variable contains value \"%s\", which cannot be parsed as an integer timeout period.%n",
environmentLoader.loadVariable(VAULT_OPEN_TIMEOUT));
logger.severe(String.format("The " + VAULT_OPEN_TIMEOUT + " environment variable contains value \"%s\", which cannot be parsed as an integer timeout period.%n",
environmentLoader.loadVariable(VAULT_OPEN_TIMEOUT)));
}
}
if (this.readTimeout == null && environmentLoader.loadVariable(VAULT_READ_TIMEOUT) != null) {
try {
this.readTimeout = Integer.valueOf(environmentLoader.loadVariable(VAULT_READ_TIMEOUT));
} catch (NumberFormatException e) {
System.err.printf("The " + VAULT_READ_TIMEOUT + " environment variable contains value \"%s\", which cannot be parsed as an integer timeout period.%n",
environmentLoader.loadVariable(VAULT_READ_TIMEOUT));
logger.severe(String.format("The " + VAULT_READ_TIMEOUT + " environment variable contains value \"%s\", which cannot be parsed as an integer timeout period.%n",
environmentLoader.loadVariable(VAULT_READ_TIMEOUT)));
}
}
if (this.sslConfig == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

/**
* This class is a container for the information returned by Vault in auth backend operations.
*/
public class AuthResponse extends VaultResponse {

private static final Logger logger = Logger.getLogger(AuthResponse.class.getCanonicalName());

private Boolean renewable;
private String authClientToken;
private String tokenAccessor;
Expand Down Expand Up @@ -58,6 +61,7 @@ public AuthResponse(final RestResponse restResponse, final int retries) {
authPolicies.add(authPolicy.asString());
}
} catch (ParseException e) {
logger.warning("RestResponse parse exception:" + e.getMessage());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;

/**
* This class is a container for the information returned by Vault in logical API
* operations (e.g. read, write).
*/
public class LogicalResponse extends VaultResponse {

private static final Logger logger = Logger.getLogger(LogicalResponse.class.getCanonicalName());

private Map<String, String> data = new HashMap<>();
private List<String> listData = new ArrayList<>();
private JsonObject dataObject = null;
Expand Down Expand Up @@ -68,7 +71,8 @@ private void parseMetadataFields() {
this.leaseId = jsonObject.get("lease_id").asString();
this.renewable = jsonObject.get("renewable").asBoolean();
this.leaseDuration = jsonObject.get("lease_duration").asLong();
} catch (Exception ignored) {
} catch (Exception e) {
logger.warning("RestResponse parse exception:" + e.getMessage());
}
}

Expand Down Expand Up @@ -105,7 +109,8 @@ private void parseResponseData(final Logical.logicalOperations operation) {
}

}
} catch (Exception ignored) {
} catch (Exception e) {
logger.warning("RestResponse parse exception:" + e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

/**
* This class is a container for the information returned by Vault in lookup operations on auth backends.
*/
public class LookupResponse extends VaultResponse {

private static final Logger logger = Logger.getLogger(LookupResponse.class.getCanonicalName());

private String accessor;
private long creationTime;
private long creationTTL;
Expand Down Expand Up @@ -69,7 +72,8 @@ public LookupResponse(final RestResponse restResponse, final int retries) {
renewable = dataJsonObject.getBoolean("renewable", false);
ttl = dataJsonObject.getLong("ttl", 0);

} catch (ParseException ignored) {
} catch (ParseException e) {
logger.warning("RestResponse parse exception:" + e.getMessage());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@
import com.bettercloud.vault.json.ParseException;
import com.bettercloud.vault.rest.RestResponse;
import java.nio.charset.StandardCharsets;
import java.util.logging.Logger;

/**
* This class is a container for the information returned by Vault in <code>v1/sys/*seal*</code>
* operations.
*/
public class SealResponse extends VaultResponse {

private static final Logger logger = Logger.getLogger(SealResponse.class.getCanonicalName());

private Boolean sealed;
private Long threshold;
private Long numberOfShares;
Expand All @@ -34,7 +38,8 @@ public SealResponse(final RestResponse restResponse, final int retries) {
numberOfShares = jsonObject.getLong("n", 0);
progress = jsonObject.getLong("progress", 0);

} catch (ParseException ignored) {
} catch (ParseException e) {
logger.warning("RestResponse parse exception:" + e.getMessage());
}
}

Expand Down