From 797b1fcdfc8daf9972f5287b6d9812597b38e9ff Mon Sep 17 00:00:00 2001 From: Shih-Hao Yeh Date: Fri, 15 Nov 2024 13:59:16 -0800 Subject: [PATCH 1/2] enhance logging --- .../test/com/netflix/evcache/test/EVCacheTestDI.java | 2 ++ .../src/main/java/com/netflix/evcache/EVCacheImpl.java | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/evcache-client/test/com/netflix/evcache/test/EVCacheTestDI.java b/evcache-client/test/com/netflix/evcache/test/EVCacheTestDI.java index e37df78c..ef44f2ff 100644 --- a/evcache-client/test/com/netflix/evcache/test/EVCacheTestDI.java +++ b/evcache-client/test/com/netflix/evcache/test/EVCacheTestDI.java @@ -94,6 +94,8 @@ public void testKeySizeCheck() throws Exception { } catch(Exception e) { exceptionThrown = true; if (log.isDebugEnabled()) log.debug("Check key length: " + longKey + ": INVALID"); + assertTrue(e.getMessage().contains(longKey), "Error message should include the invalid key."); + assertTrue(e.getMessage().contains(Integer.toString(longKey.length())), "Error message should include the key length of the invalid key."); } assertTrue(exceptionThrown); } diff --git a/evcache-core/src/main/java/com/netflix/evcache/EVCacheImpl.java b/evcache-core/src/main/java/com/netflix/evcache/EVCacheImpl.java index b17450b3..5a72efa6 100644 --- a/evcache-core/src/main/java/com/netflix/evcache/EVCacheImpl.java +++ b/evcache-core/src/main/java/com/netflix/evcache/EVCacheImpl.java @@ -215,7 +215,9 @@ EVCacheKey getEVCacheKey(final String key) { } if (canonicalKey.length() > this.maxKeyLength.get() && !hashKey.get() && !autoHashKeys.get()) { - throw new IllegalArgumentException("Key is too long (maxlen = " + this.maxKeyLength.get() + ')'); + final String errMsg = "CanonicalKey ``" + canonicalKey + "`` is too long (maxLen = " + this.maxKeyLength.get() + ", keyLen = " + key.length() + ", canonicalKeyLen = " + canonicalKey.length() + ')'; + log.error(errMsg); + throw new IllegalArgumentException(errMsg); } boolean shouldHashKeyAtAppLevel = hashKey.get() || (canonicalKey.length() > this.maxKeyLength.get() && autoHashKeys.get()); From 6d7777ef1e4b51943c4b9b80e6227bbda0f2b9ac Mon Sep 17 00:00:00 2001 From: Shih-Hao Yeh Date: Tue, 19 Nov 2024 14:51:01 -0800 Subject: [PATCH 2/2] String format --- .../src/main/java/com/netflix/evcache/EVCacheImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/evcache-core/src/main/java/com/netflix/evcache/EVCacheImpl.java b/evcache-core/src/main/java/com/netflix/evcache/EVCacheImpl.java index 5a72efa6..be1de059 100644 --- a/evcache-core/src/main/java/com/netflix/evcache/EVCacheImpl.java +++ b/evcache-core/src/main/java/com/netflix/evcache/EVCacheImpl.java @@ -215,8 +215,8 @@ EVCacheKey getEVCacheKey(final String key) { } if (canonicalKey.length() > this.maxKeyLength.get() && !hashKey.get() && !autoHashKeys.get()) { - final String errMsg = "CanonicalKey ``" + canonicalKey + "`` is too long (maxLen = " + this.maxKeyLength.get() + ", keyLen = " + key.length() + ", canonicalKeyLen = " + canonicalKey.length() + ')'; - log.error(errMsg); + final String errMsg = String.format("CanonicalKey ``%s`` is too long (maxLen = %d, keyLen = %d, canonicalKeyLen = %d)", canonicalKey, this.maxKeyLength.get(), key.length(), canonicalKey.length()); + log.warn(errMsg); throw new IllegalArgumentException(errMsg); }