Class BatchingLogClient

java.lang.Object
codes.grow.packages.betterstack.logging.BatchingLogClient
All Implemented Interfaces:
LogClient, AutoCloseable

public final class BatchingLogClient extends Object implements LogClient
LogClient built from a LogExporter, BatchOptions, resource attributes and a RedactionProcessor.

 LogClient logs = BatchingLogClient.builder(exporter)
     .resource(Map.of("service.name", "checkout"))
     .build();
 logs.logger("orders").info("order placed", Map.of("order.id", 42));
 logs.close();
 
  • Method Details

    • builder

      public static BatchingLogClient.Builder builder(LogExporter exporter)
      Returns a builder.
      Parameters:
      exporter - the service exporter
      Returns:
      builder
    • processor

      public BatchProcessor processor()
      The underlying processor.
      Returns:
      processor
    • resource

      public Map<String,Object> resource()
      Resource attributes added to every record.
      Returns:
      resource
    • send

      public void send(LogEntry entry)
      Description copied from interface: LogClient
      Enqueues one record or input. Applies redaction and defaults (timestamp = now, resource from the client, trace correlation for inputs when a span is active). Never throws for a full queue or a closed client; the record is dropped and counted instead.
      Specified by:
      send in interface LogClient
      Parameters:
      entry - a LogRecord or LogInput
    • sendBatch

      public void sendBatch(Collection<? extends LogEntry> entries)
      Description copied from interface: LogClient
      Enqueues several records or inputs.
      Specified by:
      sendBatch in interface LogClient
      Parameters:
      entries - records or inputs
    • flush

      public void flush()
      Description copied from interface: LogClient
      Exports everything queued now, waiting at most the export timeout.
      Specified by:
      flush in interface LogClient
    • flush

      public void flush(Duration timeout)
      Description copied from interface: LogClient
      Exports everything queued now.
      Specified by:
      flush in interface LogClient
      Parameters:
      timeout - maximum wait
    • flushAsync

      public CompletableFuture<Void> flushAsync(Duration timeout)
      Description copied from interface: LogClient
      Specified by:
      flushAsync in interface LogClient
      Parameters:
      timeout - maximum wait
      Returns:
      completes when the queued records were exported
    • close

      public void close()
      Description copied from interface: LogClient
      Flushes and shuts down; idempotent.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface LogClient
    • closeAsync

      public CompletableFuture<Void> closeAsync()
      Description copied from interface: LogClient
      Asynchronous LogClient.close().
      Specified by:
      closeAsync in interface LogClient
      Returns:
      completes when the client is closed
    • stats

      public BatchStats stats()
      Description copied from interface: LogClient
      Current counters.
      Specified by:
      stats in interface LogClient
      Returns:
      stats