Skip to content

Instantly share code, notes, and snippets.

@zachelrath
Last active February 15, 2022 15:20
Show Gist options
  • Save zachelrath/f6cd37768dd959b78ace8507f01f4f44 to your computer and use it in GitHub Desktop.
Save zachelrath/f6cd37768dd959b78ace8507f01f4f44 to your computer and use it in GitHub Desktop.
Structured data logging with Log4j ObjectMessage
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ItemLog {
private Integer totalItems;
private List<OrderItem> items;
public ItemLog(List<OrderItem> items) {
this.items = items;
this.totalItems = items.size();
}
}
logger.info(new ObjectMessage(new ItemLog(orderItems));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment