import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.ThreadContext;
import org.apache.logging.log4j.message.StructuredDataMessage;
public class MyService {
private static final Logger logger = LogManager.getLogger(MyService.class);
public void processOrder(String orderId) {
// This will be shown as a tag in AppSignal for all log lines
ThreadContext.put("order_id", orderId);
logger.info("Processing order");
StructuredDataMessage structuredMessage = new StructuredDataMessage(
"processing_items", // ID (not shown in AppSignal)
String.format("Processing items in order"), // Message
"order" // Type (not shown in AppSignal)
);
// This will be shown as a tag in AppSignal for this log line
structuredMessage.put("item_count", 123);
logger.info(structuredMessage);
ThreadContext.clearAll();
}
}