99import com .bettercloud .vault .response .VaultResponse ;
1010import com .bettercloud .vault .rest .RestResponse ;
1111import io .scalecube .config .utils .ThrowableUtil ;
12+ import java .lang .System .Logger ;
13+ import java .lang .System .Logger .Level ;
1214import java .nio .charset .StandardCharsets ;
1315import java .util .Objects ;
1416import java .util .Optional ;
1719import java .util .concurrent .TimeUnit ;
1820import java .util .function .Function ;
1921import java .util .function .UnaryOperator ;
20- import java .util .logging .Level ;
21- import java .util .logging .Logger ;
2222
2323public class VaultInvoker {
2424
25- private static final Logger LOGGER = Logger .getLogger (VaultInvoker .class .getName ());
25+ private static final Logger LOGGER = System .getLogger (VaultInvoker .class .getName ());
2626
2727 private static final int STATUS_CODE_FORBIDDEN = 403 ;
2828 public static final int STATUS_CODE_HEALTH_OK = 200 ;
@@ -64,7 +64,8 @@ public <T extends VaultResponse> T invoke(VaultCall<T> call) throws VaultExcepti
6464 if (e .getHttpStatusCode () == STATUS_CODE_FORBIDDEN ) {
6565 LOGGER .log (
6666 Level .WARNING ,
67- String .format ("Authentication failed: %s, now trying to recreate vault" , e ));
67+ "Authentication failed (error message: {0}), now trying to recreate vault" ,
68+ e .getMessage ());
6869 vault = recreateVault (vault );
6970 return call .apply (vault );
7071 }
@@ -101,11 +102,11 @@ private synchronized Vault recreateVault(Vault prev) throws VaultException {
101102 Level .INFO ,
102103 String .format ("Renew token timer was set to %ssec, (TTL = %ssec)" , delay , ttl ));
103104 } else {
104- LOGGER .warning ( "Vault token is not renewable" );
105+ LOGGER .log ( Level . WARNING , "Vault token is not renewable" );
105106 }
106107 this .vault = vault ;
107108 } catch (VaultException e ) {
108- LOGGER .log (Level .SEVERE , "Could not initialize and validate the vault" , e );
109+ LOGGER .log (Level .ERROR , "Could not initialize and validate the vault" , e );
109110 throw e ;
110111 }
111112 return vault ;
@@ -119,9 +120,8 @@ private void renewToken() throws VaultException {
119120 try {
120121 AuthResponse response = vault .auth ().renewSelf ();
121122 long ttl = response .getAuthLeaseDuration ();
122- if (LOGGER .isLoggable (Level .FINE )) {
123- LOGGER .log (
124- Level .FINE , String .format ("Token was successfully renewed (new TTL = %ssec)" , ttl ));
123+ if (LOGGER .isLoggable (Level .DEBUG )) {
124+ LOGGER .log (Level .DEBUG , "Token was successfully renewed (new TTL = {0}sec)" , ttl );
125125 }
126126 if (response .isAuthRenewable ()) {
127127 if (ttl > 1 ) {
@@ -133,7 +133,7 @@ private void renewToken() throws VaultException {
133133 vault = recreateVault (vault );
134134 }
135135 } else {
136- LOGGER .warning ( "Vault token is not renewable now" );
136+ LOGGER .log ( Level . WARNING , "Vault token is not renewable now" );
137137 }
138138 } catch (VaultException e ) {
139139 // try recreate Vault according to https://www.vaultproject.io/api/overview#http-status-codes
0 commit comments