From c728e1489caab45afbbbb148acb6736cfabb2b3e Mon Sep 17 00:00:00 2001 From: James Perkins Date: Tue, 28 Jun 2016 10:53:24 -0700 Subject: [PATCH] [LOGMGR-141] Fix ending deletion length when truncating format parts. --- .../java/org/jboss/logmanager/formatters/Formatters.java | 2 +- .../jboss/logmanager/formatters/PatternFormatterTests.java | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jboss/logmanager/formatters/Formatters.java b/src/main/java/org/jboss/logmanager/formatters/Formatters.java index b0814ad7..4a5a3500 100644 --- a/src/main/java/org/jboss/logmanager/formatters/Formatters.java +++ b/src/main/java/org/jboss/logmanager/formatters/Formatters.java @@ -210,7 +210,7 @@ public void render(final StringBuilder builder, final ExtLogRecord record) { final int overflow = writtenLen - maximumWidth; if (overflow > 0) { if (truncateBeginning) { - builder.delete(oldLen, overflow + 1); + builder.delete(oldLen, oldLen + overflow); } builder.setLength(newLen - overflow); } else { diff --git a/src/test/java/org/jboss/logmanager/formatters/PatternFormatterTests.java b/src/test/java/org/jboss/logmanager/formatters/PatternFormatterTests.java index d35476a1..a99d2c2e 100644 --- a/src/test/java/org/jboss/logmanager/formatters/PatternFormatterTests.java +++ b/src/test/java/org/jboss/logmanager/formatters/PatternFormatterTests.java @@ -184,6 +184,11 @@ public void truncation() throws Exception { formatter = new PatternFormatter("%-5.10m"); Assert.assertEquals("test ", formatter.format(record)); + + // Exact length truncation + final String msg = "test message"; + formatter = new PatternFormatter("%c %-5.-7m"); + Assert.assertEquals(CATEGORY + " message", formatter.format(createLogRecord(msg))); } @Test