Skip to content

Commit

Permalink
fix(logback): handle log messages with {} formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
lemnik committed Jun 8, 2022
1 parent ce5d249 commit 640b01c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
* Bump Jackson from 2.9.1 for critical vulnerability fixes
[#170](https://github.com/bugsnag/bugsnag-java/pull/170)

* Support log messages that use `{}` formatting
[]{}

## 3.6.2 (2020-11-10)

* Fix JVM hang when System.exit or bugsnag.close is not called
Expand Down
2 changes: 1 addition & 1 deletion bugsnag/src/main/java/com/bugsnag/BugsnagAppender.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public void beforeNotify(Report report) {

// Add some data from the logging event
report.addToTab("Log event data",
"Message", event.getMessage());
"Message", event.getFormattedMessage());
report.addToTab("Log event data",
"Logger name", event.getLoggerName());

Expand Down
25 changes: 25 additions & 0 deletions bugsnag/src/test/java/com/bugsnag/AppenderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
public class AppenderTest {

private static final Logger LOGGER = Logger.getLogger(AppenderTest.class);

private static final org.slf4j.Logger SLF_LOGGER = LoggerFactory.getLogger(AppenderTest.class);

private StubNotificationDelivery delivery;
private StubSessionDelivery sessionDelivery;
private Delivery originalDelivery;
Expand Down Expand Up @@ -87,6 +90,28 @@ public void testSimpleException() {
getMetaDataMap(notification, "Log event data").get("Message"));
}

@Test
public void testFormattedMessage() {
int value = 1234;

// Send a test log
SLF_LOGGER.warn("Test exception, errorCode: {}", value, new RuntimeException("test"));

String message = "no exception";
// Send a log with no exception
SLF_LOGGER.warn("Test log with {}", message);

// Check that one report was sent to Bugsnag
assertEquals(1, delivery.getNotifications().size());

// Check the correct event was created
Notification notification = delivery.getNotifications().get(0);
assertEquals("test", notification.getEvents().get(0).getExceptionMessage());
assertEquals(Severity.WARNING.getValue(), notification.getEvents().get(0).getSeverity());
assertEquals("Test exception, errorCode: " + value,
getMetaDataMap(notification, "Log event data").get("Message"));
}

@Test
public void testExceptionSeverities() {

Expand Down

0 comments on commit 640b01c

Please sign in to comment.