Skip to content

Commit

Permalink
feat: introduce log-codes for info level (#537)
Browse files Browse the repository at this point in the history
* feat: introduce log-codes for info level

* refactor: address checkstyle

refactor: address checkstyle

refactor: address checkstyle

* docs: upate README.md

* docs: update CHANGELOG.md
  • Loading branch information
tmberthold committed May 27, 2022
1 parent 8bfb61a commit d21788d
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 34 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ It is as of now possible to log incoming messages (header, not payload), send re
- ReferingConnector validation ([PR 526](https://github.com/International-Data-Spaces-Association/IDS-Messaging-Services/pull/526))

### Patch Change: Other
- Added log-codes for event severity Info ([PR 537](https://github.com/International-Data-Spaces-Association/IDS-Messaging-Services/pull/537))
- Changed `name` and `id` of `eis-ids-public` repository in pom.
- Added negative leeway for expiration of cached DAT ([PR 527](https://github.com/International-Data-Spaces-Association/IDS-Messaging-Services/pull/527))

Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,11 @@ Log-codes exist for different log-levels. They allow easy search for the code lo
Syntax: IMS-XY-L-1234, shortened to: IMSXYL1234
- IMS = IDS-Messaging-Services
- XY = Subsystem Module (CO Core, AP AppStore, BR Broker, CL ClearingHouse, ME Messaging, PA Paris, VO Vocol)
- L = Event Severity (E Error, W Warn, D Debug)
- L = Event Severity (E Error, W Warn, D Debug, I Info)
- 1234 = Log identifier

Will e.g. print as [code=(IMSCOE0001)]: IDS-Messaging-Services Core-Module Error 0001.

No log-code will be printed for log-info level.

## Other: Project-Wiki

This project has a <a href="https://github.com/International-Data-Spaces-Association/IDS-Messaging-Services/wiki">GitHub-Wiki</a> where more details about the individual java-modules and their functionalities are documented.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public ConfigProducer(final ConfigProperties properties,
try {
configModel = loadConfig(properties);
if (log.isInfoEnabled()) {
log.info("Successfully imported configuration.");
log.info("Successfully imported configuration. [code=(IMSCOI0048)]");
}
} catch (IOException e) {
if (log.isErrorEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ private KeyStore loadKeyStore(final char[] pw, final URI location, final String
}
}
if (log.isInfoEnabled()) {
log.info("Successfully loaded {}.", keyStoreType);
log.info("Successfully loaded {}. [code=(IMSCOI0049)]", keyStoreType);
}
return store;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public static boolean verify(final Claims toVerify) throws ClaimsException {
}
}
if (log.isInfoEnabled()) {
log.info("Successfully verified DAT claims.");
log.info("Successfully verified DAT claims. [code=(IMSCOI0050)]");
}

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public Key requestPublicKey(@NonNull final String issuer, @NonNull final String

if (log.isInfoEnabled()) {
log.info("Requesting public key of token issuer. "
+ "[url=({}), kid=({})]", pubKeysUrl, kid);
+ "[url=({}), kid=({}), code=(IMSCOI0051)]", pubKeysUrl, kid);
}

final var client = clientProvider.getClient();
Expand Down Expand Up @@ -240,10 +240,11 @@ private boolean isExpired() {
if (currentJwt != null) {
//Will only log if DAT was successfully acquired.
if (expired && log.isInfoEnabled()) {
log.info("Cached DAPS DAT expired or no expiration set. [expiration=({})]",
log.info("Cached DAPS DAT expired or no expiration set."
+ " [expiration=({}), code=(IMSCOI0052)]",
expiration);
} else if (log.isInfoEnabled()) {
log.info("Using cached DAPS DAT. [expiration=({})]",
log.info("Using cached DAPS DAT. [expiration=({}), code=(IMSCOI0053)]",
expiration);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,10 @@ public String acquireToken(final String dapsUrl)

if (jwtResponse.isSuccessful() && log.isInfoEnabled()) {
if (logDapsResponse) {
log.info("Successfully received DAT from DAPS. [response=({})]", jwtString);
log.info("Successfully received DAT from DAPS."
+ " [response=({}), code=(IMSCOI0053)]", jwtString);
} else {
log.info("Successfully received DAT from DAPS.");
log.info("Successfully received DAT from DAPS. [code=(IMSCOI0054)]");
}
}
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class PostConfigInterceptor implements PostConfigProducerInterceptor {
@Override
public void perform(final ConfigContainer configContainer) {
if (log.isInfoEnabled()) {
log.info("Modifying configuration using interceptor interface.");
log.info("Modifying configuration using interceptor interface. [code=(IMSCOI0047)]");
}
final var conf = configContainer.getConfigurationModel();
conf.setProperty("modified", true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public ConfigurationModel perform(final ConfigProperties properties)
throws ConfigProducerInterceptorException {
try {
if (log.isInfoEnabled()) {
log.info("Intercepting loading of configuration!");
log.info("Intercepting loading of configuration! [code=(IMSCOI0055)]");
}
final var config = loadConfig(properties);
config.setProperty("preInterceptor", true);
Expand All @@ -61,7 +61,7 @@ private ConfigurationModel loadConfig(final ConfigProperties properties)
final var config = getConfiguration(properties);

if (log.isInfoEnabled()) {
log.info("Importing configuration from file.");
log.info("Importing configuration from file. [code=(IMSCOI0056)]");
}

return SERIALIZER.deserialize(config, ConfigurationModel.class);
Expand All @@ -77,7 +77,7 @@ private String getConfiguration(final ConfigProperties properties) throws IOExce

private String getClassPathConfig(final ConfigProperties properties) throws IOException {
if (log.isInfoEnabled()) {
log.info("Loading config from classpath: {}", properties.getPath());
log.info("Loading config from classpath: {} [code=(IMSCOI0057)]", properties.getPath());
}

final var configurationStream = new ClassPathResource(properties.getPath()).getInputStream();
Expand All @@ -89,7 +89,7 @@ private String getClassPathConfig(final ConfigProperties properties) throws IOEx

private String getAbsolutePathConfig(final ConfigProperties properties) throws IOException {
if (log.isInfoEnabled()) {
log.info("Loading config from absolute Path {}",
log.info("Loading config from absolute Path {} [code=(IMSCOI0058)]",
properties.getPath());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public ResponseEntity<MultiValueMap<String, Object>> handleIDSMessage(
final HttpServletRequest request) {
try {
if (log.isInfoEnabled()) {
log.info("Received incoming message.");
log.info("Received incoming message. [code=(IMSMEI0059)]");
}

final var headerPart =
Expand All @@ -141,13 +141,7 @@ public ResponseEntity<MultiValueMap<String, Object>> handleIDSMessage(
}

final var headerBytes = IOUtils.toByteArray(headerPart.getInputStream());
if (Boolean.TRUE.equals(logIncoming)) {
final var headerInput = new ByteArrayInputStream(headerBytes);
log.info("Incoming message header: {}",
IOUtils.toString(headerInput, StandardCharsets.UTF_8));
headerInput.close();
}

logIncomingMessage(headerBytes);
String input;

if (log.isDebugEnabled()) {
Expand Down Expand Up @@ -205,7 +199,7 @@ public ResponseEntity<MultiValueMap<String, Object>> handleIDSMessage(
// return the ResponseEntity as Multipart content
// with created MultiValueMap
if (log.isInfoEnabled()) {
log.info("Sending response with status OK (200).");
log.info("Sending response with status OK (200). [code=(IMSMEI0061)]");
}

logResponseHeader(responseAsMap);
Expand All @@ -224,7 +218,8 @@ public ResponseEntity<MultiValueMap<String, Object>> handleIDSMessage(
}

if (log.isInfoEnabled()) {
log.info("Sending response with status OK (200) without body.");
log.info("Sending response with status OK (200) without body."
+ " [code=(IMSMEI0062)]");
}

return ResponseEntity
Expand Down Expand Up @@ -269,10 +264,19 @@ public ResponseEntity<MultiValueMap<String, Object>> handleIDSMessage(
}
}

private void logIncomingMessage(final byte[] headerBytes) throws IOException {
if (Boolean.TRUE.equals(logIncoming)) {
final var headerInput = new ByteArrayInputStream(headerBytes);
log.info("Incoming message header: {} [code=(IMSMEI0060)]",
IOUtils.toString(headerInput, StandardCharsets.UTF_8));
headerInput.close();
}
}

private void logResponseHeader(final MultiValueMap<String, Object> responseAsMap) {
if (Boolean.TRUE.equals(logResponse)) {
final var header = responseAsMap.get(MultipartDatapart.HEADER.toString()).toString();
log.info("Send response header: {}", header);
log.info("Send response header: {} [code=(IMSMEI0063)]", header);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ private Map<String, String> checkDatFromResponse(final Response response)
}

if (log.isInfoEnabled()) {
log.info("Successfully passed SHACL-Validation.");
log.info("Successfully passed SHACL-Validation. [code=(IMSMEI0064)]");
}
}

Expand Down Expand Up @@ -409,15 +409,15 @@ private Response sendRequest(final Request request,
}

if (log.isInfoEnabled()) {
log.info("Sending request to {} ...", request.url());
log.info("Sending request to {} ... [code=(IMSMEI0065)]", request.url());
}

var response = client.newCall(request).execute();
final var responseBody = response.body();

if (Boolean.TRUE.equals(logResponses) && responseBody != null) {
final var bodyString = responseBody.string();
log.info("Incoming response body: {}", bodyString);
log.info("Incoming response body: {} [code=(IMSMEI0066)]", bodyString);
final var body = ResponseBody.create(bodyString, responseBody.contentType());
response = response.newBuilder().body(body).build();
}
Expand All @@ -429,7 +429,7 @@ private Response sendRequest(final Request request,
}
} else {
if (log.isInfoEnabled()) {
log.info("Successfully received response to request.");
log.info("Successfully received response to request. [code=(IMSMEI0067)]");
}
}

Expand All @@ -446,7 +446,7 @@ private void logRequest(final Request request) throws IOException {
final var requestCopy = request.newBuilder().build();
final var buffer = new Buffer();
requestCopy.body().writeTo(buffer);
log.info("Sending request message: {}", buffer.readUtf8());
log.info("Sending request message: {} [code=(IMSMEI0068)]", buffer.readUtf8());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static String printRequest(final Request request) {
*/
public static void logRequest(final Request request) {
if (log.isInfoEnabled()) {
log.info(printRequest(request));
log.info(printRequest(request) + " [code=(IMSMEI0069)]");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void testParseMultipart() throws Exception {
final var multipartString = buffer.readUtf8();

if (log.isInfoEnabled()) {
log.info(multipartString);
log.info(multipartString + " [code=(IMSMEI0070)]");
}

//parse the string and check if header and payload were parsed correctly
Expand Down

0 comments on commit d21788d

Please sign in to comment.