Skip to content

Commit

Permalink
Fixed logging problem with JDK System.Logger
Browse files Browse the repository at this point in the history
Message format placeholders "{}" aren't  used correctly in v0.0.2.
  • Loading branch information
privatestatic committed Dec 8, 2023
1 parent 39da1cb commit 64953df
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ private RawPacket[] transformArray(
if ((exceptionCounter.get() % EXCEPTIONS_TO_LOG) == 0
|| exceptionCounter.get() == 1)
{
logger.log(ERROR, "Failed to " + logMessage + " RawPacket(s)!", t);
logger.log(ERROR, "Failed to {0} RawPacket(s)!\n{1}", logMessage, t);
}
if (t instanceof Error)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ private SrtcpCryptoContext getContext(
}
catch (GeneralSecurityException e)
{
logger.log(ERROR, "Could not get context for ssrc " + ssrc, e);
logger.log(ERROR, "Could not get context for ssrc {0}.\n{1}", ssrc, e);
return null;
}
contexts.put(ssrc, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ private SrtpCryptoContext getContext(
}
catch (GeneralSecurityException e)
{
logger.log(ERROR, "Could not get context for ssrc " + ssrc, e);
logger.log(ERROR, "Could not get context for ssrc {0}.\n{1}", ssrc, e);
return null;
}
contexts.put(ssrc, context);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/jitsi/srtp/SrtcpCryptoContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ private SrtpErrorStatus processPacketAesGcm(ByteArrayBuffer pkt, int index,
{
if (encrypting)
{
logger.log(INFO, "Error encrypting SRTCP packet: {}", e.getMessage());
logger.log(INFO, "Error encrypting SRTCP packet: {0}", e.getMessage());
return SrtpErrorStatus.FAIL;
}
else
Expand All @@ -293,7 +293,7 @@ private SrtpErrorStatus processPacketAesGcm(ByteArrayBuffer pkt, int index,
}
else
{
logger.log(INFO, "Error decrypting SRTCP packet: {}", e.getMessage());
logger.log(INFO, "Error decrypting SRTCP packet: {0}", e.getMessage());
return SrtpErrorStatus.FAIL;
}
}
Expand Down Expand Up @@ -519,7 +519,7 @@ else if (policy.getEncType() == SrtpPolicy.AESF8_ENCRYPTION ||
private void logReplayWindow(long newIdx)
{
if (logger.isLoggable(DEBUG))
logger.log(DEBUG, "Updated replay window with {}. {}", newIdx,
logger.log(DEBUG, "Updated replay window with {0}. {1}", newIdx,
SrtpPacketUtils.formatReplayWindow(receivedIndex, replayWindow, REPLAY_WINDOW_SIZE));
}

Expand Down
22 changes: 11 additions & 11 deletions src/main/java/org/jitsi/srtp/SrtpCryptoContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ else if (-delta >= REPLAY_WINDOW_SIZE)
if (sender)
{
logger.log(ERROR,
"Discarding RTP packet with sequence number {}, SSRC {} because it is outside the replay"
+ " window! (roc {}, s_l {}, guessedROC {})",
"Discarding RTP packet with sequence number {0}, SSRC {1} because it is outside the replay"
+ " window! (roc {2}, s_l {3}, guessedROC {4})",
seqNo, (0xFFFFFFFFL & ssrc), roc, s_l, guessedROC);
}
return SrtpErrorStatus.REPLAY_OLD; // Packet too old.
Expand All @@ -241,8 +241,8 @@ else if (((replayWindow >>> (-delta)) & 0x1) != 0)
if (sender)
{
logger.log(ERROR,
"Discarding RTP packet with sequence number {}, SSRC {} because it has been received already!"
+ " (roc {}, s_l {}, guessedROC {})",
"Discarding RTP packet with sequence number {0}, SSRC {1} because it has been received already!"
+ " (roc {2}, s_l {3}, guessedROC {4})",
seqNo, (0xFFFFFFFFL & ssrc), roc, s_l, guessedROC);
}
return SrtpErrorStatus.REPLAY_FAIL; // Packet received already!
Expand Down Expand Up @@ -625,7 +625,7 @@ private SrtpErrorStatus processPacketAesGcm(ByteArrayBuffer pkt, boolean encrypt
{
if (encrypting)
{
logger.log(INFO, "Error encrypting SRTP packet: {}", e.getMessage());
logger.log(INFO, "Error encrypting SRTP packet: {0}", e.getMessage());
return SrtpErrorStatus.FAIL;
}
else
Expand All @@ -636,7 +636,7 @@ private SrtpErrorStatus processPacketAesGcm(ByteArrayBuffer pkt, boolean encrypt
}
else
{
logger.log(INFO, "Error decrypting SRTP packet: {}", e.getMessage());
logger.log(INFO, "Error decrypting SRTP packet: {0}", e.getMessage());
return SrtpErrorStatus.FAIL;
}
}
Expand Down Expand Up @@ -721,8 +721,8 @@ public synchronized SrtpErrorStatus reverseTransformPacket(ByteArrayBuffer pkt,

int seqNo = SrtpPacketUtils.getSequenceNumber(pkt);

logger.log(TRACE, "Reverse transform for SSRC {} SeqNo={} s_l={} seqNumSet={} guessedROC={} roc={}", this.ssrc,
seqNo, s_l, seqNumSet, guessedROC, roc);
logger.log(TRACE, "Reverse transform for SSRC {0} SeqNo={1} s_l={2} seqNumSet={3} guessedROC={4} roc={5}",
this.ssrc, seqNo, s_l, seqNumSet, guessedROC, roc);

// Whether s_l was initialized while processing this packet.
boolean seqNumWasJustSet = false;
Expand Down Expand Up @@ -776,14 +776,14 @@ public synchronized SrtpErrorStatus reverseTransformPacket(ByteArrayBuffer pkt,
}
else
{
logger.log(DEBUG, "SRTP auth failed for SSRC {}", ssrc);
logger.log(DEBUG, "SRTP auth failed for SSRC {0}", ssrc);
}

ret = err;
}
else
{
logger.log(DEBUG, "SRTP auth failed for SSRC {}", ssrc);
logger.log(DEBUG, "SRTP auth failed for SSRC {0}", ssrc);
ret = err;
}
}
Expand Down Expand Up @@ -903,7 +903,7 @@ public synchronized SrtpErrorStatus transformPacket(ByteArrayBuffer pkt)
private void logReplayWindow(long newIdx)
{
if (logger.isLoggable(TRACE))
logger.log(TRACE, "Updated replay window with {}. {}", newIdx,
logger.log(TRACE, "Updated replay window with {0}. {1}", newIdx,
SrtpPacketUtils.formatReplayWindow((roc << 16 | s_l), replayWindow, REPLAY_WINDOW_SIZE));
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jitsi/srtp/crypto/Aes.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static Cipher createCipher(String transformation)
}
catch (Exception e)
{
logger.log(WARNING, "Failed to initialize an optimized AES implementation: {}",
logger.log(WARNING, "Failed to initialize an optimized AES implementation: {0}",
e.getLocalizedMessage());
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jitsi/srtp/crypto/CipherFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public Cipher createCipher(String transformation)
{
Cipher cipher = Cipher.getInstance(transformation);
if (logger.isLoggable(DEBUG))
logger.log(DEBUG, "Using '{}' to provide cipher for transformation '{}'.",
logger.log(DEBUG, "Using {0} to provide cipher for transformation {1}.",
Optional.ofNullable(cipher).map(Cipher::getProvider).map(Provider::getName).orElse("unknown"),
transformation);
return cipher;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jitsi/srtp/crypto/HmacSha1.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static Mac createMac()
{
Mac mac = Mac.getInstance("HmacSHA1");
if (logger.isLoggable(DEBUG))
logger.log(DEBUG, "Using '{}' for HMAC",
logger.log(DEBUG, "Using {0} for HMAC",
Optional.ofNullable(mac).map(Mac::getProvider).map(Provider::getName).orElse("unknown"));
return mac;
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/jitsi/srtp/LiveTestIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void decryptWriteAndEncryptWholeStream() throws FileNotFoundException, IOExcepti
File parentFile = new File(PCAP_20230801_09_20000);
File outputFile = new File(parentFile.getParentFile(), "result.pcap");

LOGGER.log(Level.INFO, "Created new pcap file: " + outputFile);
LOGGER.log(Level.INFO, "Created new pcap file: {0}", outputFile);
PcapOutputStream out = pcap.createOutputStream(new FileOutputStream(outputFile));

try {
Expand Down

0 comments on commit 64953df

Please sign in to comment.