Package io.github.merlimat.slog
Class Logger.Builder
java.lang.Object
io.github.merlimat.slog.Logger.Builder
- Enclosing class:
- Logger
A builder for constructing a child logger with multiple context attributes
batched into a single chain node, avoiding intermediate Logger instances.
-
Method Summary
Modifier and TypeMethodDescriptionAdds a context attribute to the child logger being built.build()Builds and returns the child logger with all accumulated attributes as a single chain node.Inherits all context attributes from another logger.
-
Method Details
-
ctx
Inherits all context attributes from another logger. Can be called multiple times to compose context from several sources — attrs are appended in call order.Logger log = Logger.get(MyClass.class).with() .ctx(producerLog) // adds topic, clientAddr .ctx(requestLog) // adds requestId, traceId .attr("extra", v) .build(); // order: producerLog attrs → requestLog attrs → extra- Parameters:
other- the logger whose context to inherit- Returns:
- this builder, for chaining
-
attr
Adds a context attribute to the child logger being built.- Parameters:
key- the attribute namevalue- the attribute value- Returns:
- this builder, for chaining
-
build
Builds and returns the child logger with all accumulated attributes as a single chain node.- Returns:
- a new
Loggerwith the added context attributes
-