Class Logger.Builder

java.lang.Object
io.github.merlimat.slog.Logger.Builder
Enclosing class:
Logger

public static final class Logger.Builder extends Object
A builder for constructing a child logger with multiple context attributes batched into a single chain node, avoiding intermediate Logger instances.
  • Method Details

    • ctx

      public Logger.Builder ctx(Logger other)
      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

      public Logger.Builder attr(String key, Object value)
      Adds a context attribute to the child logger being built.
      Parameters:
      key - the attribute name
      value - the attribute value
      Returns:
      this builder, for chaining
    • build

      public Logger build()
      Builds and returns the child logger with all accumulated attributes as a single chain node.
      Returns:
      a new Logger with the added context attributes