Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
osiegmar committed Oct 16, 2023
1 parent f0556c8 commit abb58ee
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 15 deletions.
5 changes: 2 additions & 3 deletions src/main/java/de/siegmar/logbackgelf/GelfMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,8 @@ public StringBuilder toJSON() {
.appendToJSONUnquoted("timestamp", timestampToGelfNotation(timestamp))
.appendToJSONUnquoted("level", level);

for (final Map.Entry<String, Object> entry : additionalFields.entrySet()) {
jsonEncoder.appendToJSON('_' + entry.getKey(), entry.getValue());
}
additionalFields
.forEach((key, value) -> jsonEncoder.appendToJSON('_' + key, value));
}

return sb;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@

package de.siegmar.logbackgelf.custom;

import java.io.IOException;
import java.io.OutputStream;
import java.io.UncheckedIOException;
import java.nio.charset.StandardCharsets;
import java.security.DigestOutputStream;
import java.security.MessageDigest;
import java.util.Map;

Expand All @@ -49,14 +45,7 @@ protected GelfMessage buildGelfMessage(final long timestamp, final int logLevel,

private static String buildHash(final GelfMessage gelfMessage) {
final MessageDigest digest = new SHA256.Digest();

try (DigestOutputStream dos = new DigestOutputStream(OutputStream.nullOutputStream(), digest)) {
dos.write(gelfMessage.toJSON().toString().getBytes(StandardCharsets.UTF_8));
} catch (final IOException e) {
throw new UncheckedIOException(e);
}

return toHex(digest.digest());
return toHex(digest.digest(gelfMessage.toJSON().toString().getBytes(StandardCharsets.UTF_8)));
}

private static String toHex(final byte[] data) {
Expand Down

0 comments on commit abb58ee

Please sign in to comment.