# InMemoryLogBuffer

> **Class** in `deepagents_code`

📖 [View in docs](https://reference.langchain.com/python/deepagents-code/_debug_buffer/InMemoryLogBuffer)

Logging handler retaining the most recent structured records in memory.

Retention is partitioned by level: each recognized level name (see
`LOG_LEVELS`) keeps its own bounded `deque` of *capacity* records, while
unrecognized names share the `_FALLBACK_LEVEL_BUCKET` deque. A burst of
high-volume records at one recognized level (typically `DEBUG`) therefore
cannot evict the rarer, higher-severity records at other recognized levels,
so the Debug Console's level filter can still surface them. Each retained
record is tagged with its monotonic emission sequence number so snapshots
stay chronologically ordered across levels.

## Signature

```python
InMemoryLogBuffer(
    self,
    capacity: int = DEFAULT_CAPACITY,
)
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `capacity` | `int` | No | Maximum records to retain per level; oldest are dropped first. (default: `DEFAULT_CAPACITY`) |

## Extends

- `logging.Handler`

## Constructors

```python
__init__(
    self,
    capacity: int = DEFAULT_CAPACITY,
) -> None
```

| Name | Type |
|------|------|
| `capacity` | `int` |


## Properties

- `total_emitted`

## Methods

- [`emit()`](https://reference.langchain.com/python/deepagents-code/_debug_buffer/InMemoryLogBuffer/emit)
- [`snapshot_records_since()`](https://reference.langchain.com/python/deepagents-code/_debug_buffer/InMemoryLogBuffer/snapshot_records_since)

---

[View source on GitHub](https://github.com/langchain-ai/deepagents/blob/e4c1ffe9ee63d7854147de490ca27495ef157a7b/libs/code/deepagents_code/_debug_buffer.py#L61)