# opentelemetry.sdk._logs.export

class opentelemetry.sdk._logs.export.BatchLogRecordProcessor(exporter, schedule_delay_millis=None, max_export_batch_size=None, export_timeout_millis=None, max_queue_size=None, *, meter_provider=None)

  Bases: `LogRecordProcessor`

  This is an implementation of LogRecordProcessor which creates batches of received logs and sends them to the configured LogRecordExporter.

  `BatchLogRecordProcessor` is configurable with the following environment variables which correspond to constructor parameters:

  - `OTEL_BLRP_SCHEDULE_DELAY`

  - `OTEL_BLRP_MAX_QUEUE_SIZE`

  - `OTEL_BLRP_MAX_EXPORT_BATCH_SIZE`

  - `OTEL_BLRP_EXPORT_TIMEOUT`

  All the logic for emitting logs, shutting down etc. resides in the BatchProcessor class.

  on_emit(log_record)

    Emits the `ReadWriteLogRecord`.

    Implementers should handle any exceptions raised during log processing to prevent application crashes. See the class docstring for details on error handling expectations.

    Return type:

      `None`

  shutdown()

    Called when a `opentelemetry.sdk._logs.Logger` is shutdown

  force_flush(timeout_millis=None)

    Export all the received logs to the configured Exporter that have not yet been exported.

    Parameters:

      timeout_millis (`int` | `None`) – The maximum amount of time to wait for logs to be exported.

    Return type:

      `bool`

    Returns:

      False if the timeout is exceeded, True otherwise.

class opentelemetry.sdk._logs.export.ConsoleLogExporter(out=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, formatter=<function ConsoleLogRecordExporter.<lambda>>)

  Bases: `ConsoleLogRecordExporter`

class opentelemetry.sdk._logs.export.ConsoleLogRecordExporter(out=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, formatter=<function ConsoleLogRecordExporter.<lambda>>)

  Bases: `LogRecordExporter`

  Implementation of `LogRecordExporter` that prints log records to the console.

  This class can be used for diagnostic purposes. It prints the exported log records to the console STDOUT.

  export(batch)

    Exports a batch of logs.

    Parameters:

      batch (`Sequence`[`ReadableLogRecord`]) – The list of `ReadableLogRecord` objects to be exported.

    Returns:

      The result of the export.

    Raises:

      Exception – This method may raise exceptions on network errors, timeouts, or other failures. Callers (i.e., log processors) should handle these exceptions to comply with OpenTelemetry error handling principles.

  shutdown()

    Shuts down the exporter.

    Called when the SDK is shut down.

class opentelemetry.sdk._logs.export.LogExporter(**kwargs)

  Bases: `LogRecordExporter`

class opentelemetry.sdk._logs.export.LogRecordExporter

  Bases: `ABC`

  Interface for exporting logs.

  Interface to be implemented by services that want to export logs received in their own format.

  To export data this MUST be registered to the `opentelemetry.sdk._logs.Logger` using a log processor.

  Important

  The `export()` method may raise exceptions (e.g., network errors, timeouts, serialization errors). It is the responsibility of the `LogRecordProcessor` calling this exporter to handle these exceptions appropriately to prevent application crashes. See `LogRecordProcessor` for guidance on implementing proper error handling.

  abstractmethod export(batch)

    Exports a batch of logs.

    Parameters:

      batch (`Sequence`[`ReadableLogRecord`]) – The list of `ReadableLogRecord` objects to be exported.

    Return type:

      `LogRecordExportResult`

    Returns:

      The result of the export.

    Raises:

      Exception – This method may raise exceptions on network errors, timeouts, or other failures. Callers (i.e., log processors) should handle these exceptions to comply with OpenTelemetry error handling principles.

  abstractmethod shutdown()

    Shuts down the exporter.

    Called when the SDK is shut down.

class opentelemetry.sdk._logs.export.LogExportResult(*values)

  Bases: `Enum`

  SUCCESS = 0
  FAILURE = 1

class opentelemetry.sdk._logs.export.LogRecordExportResult(*values)

  Bases: `Enum`

  SUCCESS = 0
  FAILURE = 1

class opentelemetry.sdk._logs.export.SimpleLogRecordProcessor(exporter, *, meter_provider=None)

  Bases: `LogRecordProcessor`

  Implementation of LogRecordProcessor that exports logs synchronously.

  This processor passes received logs directly to the configured `LogRecordExporter` as soon as they are emitted.

  This class serves as a reference implementation for custom log processors, demonstrating proper error handling. Note how the `on_emit` method wraps the exporter call in a try/except block to prevent exceptions from propagating to the application.

  on_emit(log_record)

    Emits the `ReadWriteLogRecord`.

    Implementers should handle any exceptions raised during log processing to prevent application crashes. See the class docstring for details on error handling expectations.

  shutdown()

    Called when a `opentelemetry.sdk._logs.Logger` is shutdown

  force_flush(timeout_millis=30000)

    Export all the received logs to the configured Exporter that have not yet been exported.

    Parameters:

      timeout_millis (`int`) – The maximum amount of time to wait for logs to be exported.

    Return type:

      `bool`

    Returns:

      False if the timeout is exceeded, True otherwise.

class opentelemetry.sdk._logs.export.InMemoryLogExporter(**kwargs)

  Bases: `InMemoryLogRecordExporter`

class opentelemetry.sdk._logs.export.InMemoryLogRecordExporter

  Bases: `LogRecordExporter`

  Implementation of `LogRecordExporter` that stores logs in memory.

  This class can be used for testing purposes. It stores the exported logs in a list in memory that can be retrieved using the `get_finished_logs()` method.

  clear()
    Return type:

      `None`

  get_finished_logs()
    Return type:

      `tuple`[`ReadableLogRecord`, `...`]

  export(batch)

    Exports a batch of logs.

    Parameters:

      batch (`Sequence`[`ReadableLogRecord`]) – The list of `ReadableLogRecord` objects to be exported.

    Return type:

      `LogRecordExportResult`

    Returns:

      The result of the export.

    Raises:

      Exception – This method may raise exceptions on network errors, timeouts, or other failures. Callers (i.e., log processors) should handle these exceptions to comply with OpenTelemetry error handling principles.

  shutdown()

    Shuts down the exporter.

    Called when the SDK is shut down.

    Return type:

      `None`