> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bioptimus.com/llms.txt
> Use this file to discover all available pages before exploring further.

# bioptimus.observability.log_export

Redacting readers over the structured log files.

Reads the JSON log file `bioptimus.observability.logging` writes and returns its entries as mappings, anonymized by default so the result is suitable to export in a support bundle or the server `/diagnostics` response. This redaction is best-effort, not a guarantee (see `bioptimus.observability.anonymize`). Two views are provided: [`read_recent_logs`](/sdk-reference/observability/log_export#read_recent_logs) tails the active file, and [`read_usage_records`](/sdk-reference/observability/log_export#read_usage_records) selects model-request usage entries across the active file and all of its rotations. Both resolve the log file exactly as `bioptimus.observability.logging.configure_logging` does and reuse the same per-field anonymization policy as emission-time redaction.

***

#### USAGE\_EVENT

Structured-log `event` slug identifying a model-request usage record. The API server emits it on every inference, embedding, and metadata call, so [`read_usage_records`](/sdk-reference/observability/log_export#read_usage_records) can select these entries for usage reporting.

***

#### read\_recent\_logs

```python theme={null}
def read_recent_logs(log_file: str | Path | None = None,
                     *,
                     max_entries: int = _DEFAULT_LOG_TAIL,
                     anonymize: bool = True) -> list[dict[str, Any]]
```

Reads the most recent entries from the active log file.

Resolves the log file the same way [`configure_logging`](/sdk-reference/observability/logging#configure_logging) does: from `log_file` when given, otherwise the `BIOPTIMUS_LOG_FILE` environment variable, otherwise [`default_log_file`](/sdk-reference/observability/logging#default_log_file). Reads up to the last `max_entries` lines, parses each structured JSON line into a mapping, and (by default) anonymizes it exactly as it is anonymized at emission. A line that is not JSON is wrapped as a `{"message": ...}` entry with embedded slide paths and user names scrubbed.

Only the active log file is read; rotated files are left to the support bundle, which archives the full history. When file logging is disabled (`BIOPTIMUS_LOG_FILE` set empty) or the file does not yet exist, an empty list is returned.

<ParamField body="log_file">
  Path to the log file to read. When omitted, the `BIOPTIMUS_LOG_FILE` environment variable supplies it and, if that is unset, [`default_log_file`](/sdk-reference/observability/logging#default_log_file).
</ParamField>

<ParamField body="max_entries">
  Maximum number of trailing entries to return.
</ParamField>

<ParamField body="anonymize">
  When `True` (the default), redacts PII from each entry so the result is safe to export.
</ParamField>

**Returns**:

Recent log entries, oldest first, each as a mapping.

***

#### read\_usage\_records

```python theme={null}
def read_usage_records(log_file: str | Path | None = None,
                       *,
                       anonymize: bool = True) -> list[dict[str, Any]]
```

Reads every model-request usage record from the active and rotated logs.

Selects the structured log entries whose `event` is `USAGE_EVENT` across the active log file and all of its rotations, so the result is the complete usage history rather than the recent tail [`read_recent_logs`](/sdk-reference/observability/log_export#read_recent_logs) returns. Records are returned oldest first: the rotated files (ordered by their date suffix) precede the active file, and entries within each file keep their append order. Each record is anonymized the same way it was at emission unless `anonymize` is `False`.

The log file is resolved exactly as by [`configure_logging`](/sdk-reference/observability/logging#configure_logging): from `log_file` when given, otherwise the `BIOPTIMUS_LOG_FILE` environment variable, otherwise [`default_log_file`](/sdk-reference/observability/logging#default_log_file). When file logging is disabled (`BIOPTIMUS_LOG_FILE` set empty) or no log file exists yet, an empty list is returned.

<ParamField body="log_file">
  Path to the active log file. When omitted, the `BIOPTIMUS_LOG_FILE` environment variable supplies it and, if that is unset, [`default_log_file`](/sdk-reference/observability/logging#default_log_file). Rotated files sharing the same base name are read automatically.
</ParamField>

<ParamField body="anonymize">
  When `True` (the default), redacts PII from each record so the result is safe to export.
</ParamField>

**Returns**:

Every usage record, oldest first, each as a mapping.
