Fluent Syntax
ByteHide Logger supports a fluent API that lets you chain multiple features in a single, readable expression. Build rich log entries with metadata, context, tags, and correlation IDs.
Fluent API Methods
| Method | Description |
|---|---|
Log.withTags(String...) | Add categorization tags |
Log.withContext(String, Object) | Add contextual key-value pair |
Log.withCorrelationId(String) | Set correlation ID for request tracking |
Log.withException(Exception) | Attach exception details |
Log.withMetadata(String, Object) | Add metadata key-value pair |
Basic Chaining
Java
Log.withTags("api", "request")
.withContext("endpoint", "/users")
.withContext("method", "GET")
.info("API request received");Log.withTags("api", "request")
.withContext("endpoint", "/users")
.withContext("method", "GET")
.info("API request received");Advanced Chaining
Full Feature Chain
Java
Log.withCorrelationId("req-123")
.withTags("payment", "critical")
.withContext("orderId", "ORD-001")
.withContext("amount", 99.99)
.withMetadata("processingTimeMs", 250)
.info("Payment processed");Log.withCorrelationId("req-123")
.withTags("payment", "critical")
.withContext("orderId", "ORD-001")
.withContext("amount", 99.99)
.withMetadata("processingTimeMs", 250)
.info("Payment processed");Error Handling Chain
Java
try {
processPayment(request);
} catch (Exception e) {
Log.withCorrelationId(correlationId)
.withTags("payment", "error")
.withContext("orderId", request.getOrderId())
.withContext("amount", request.getAmount())
.withException(e)
.error("Payment processing failed");
}try {
processPayment(request);
} catch (Exception e) {
Log.withCorrelationId(correlationId)
.withTags("payment", "error")
.withContext("orderId", request.getOrderId())
.withContext("amount", request.getAmount())
.withException(e)
.error("Payment processing failed");
}Performance Monitoring Chain
Java
long startTime = System.currentTimeMillis();
List<Product> products = repository.findAll();
long elapsed = System.currentTimeMillis() - startTime;
Log.withTags("database", "performance")
.withContext("query", "findAllProducts")
.withContext("resultCount", products.size())
.withMetadata("queryTimeMs", elapsed)
.info("Database query completed");long startTime = System.currentTimeMillis();
List<Product> products = repository.findAll();
long elapsed = System.currentTimeMillis() - startTime;
Log.withTags("database", "performance")
.withContext("query", "findAllProducts")
.withContext("resultCount", products.size())
.withMetadata("queryTimeMs", elapsed)
.info("Database query completed");Patterns
Request Processing Pattern
Java
public void processRequest(Request request) {
String correlationId = java.util.UUID.randomUUID().toString();
// Start
Log.withCorrelationId(correlationId)
.withTags("request", "start")
.withContext("type", request.getType())
.info("Request processing started");
// Processing
Log.withCorrelationId(correlationId)
.withTags("request", "processing")
.debug("Validating request data");
// Complete
Log.withCorrelationId(correlationId)
.withTags("request", "complete")
.withMetadata("totalTimeMs", elapsed)
.info("Request processing completed");
}public void processRequest(Request request) {
String correlationId = java.util.UUID.randomUUID().toString();
// Start
Log.withCorrelationId(correlationId)
.withTags("request", "start")
.withContext("type", request.getType())
.info("Request processing started");
// Processing
Log.withCorrelationId(correlationId)
.withTags("request", "processing")
.debug("Validating request data");
// Complete
Log.withCorrelationId(correlationId)
.withTags("request", "complete")
.withMetadata("totalTimeMs", elapsed)
.info("Request processing completed");
}Best Practices
Fluent Syntax Best Practices
- Start with the most specific identifier (correlation ID or tags)
- Add context progressively from general to specific
- Keep chains readable by using proper indentation
- Terminate with the appropriate log level method