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

# Writer

> Writer utilities for logging and instrumentation utilities for tracking ai model interactions.

[View module source on GitHub](https://github.com/maximhq/maxim-py/blob/main/maxim/logger/writer.py)

Module for handling log writing operations in the [Maxim](/sdk/python/references/maxim) SDK.

This module provides classes for configuring and managing log writing,
including automatic flushing, file-based persistence, and API integration.

## [LogWriterConfig](/sdk/python/references/logger/writer)

```python theme={null}
class LogWriterConfig()
```

Configuration class for the [LogWriter](/sdk/python/references/logger/writer).

**Attributes**:

| Name               | Description                                                 |
| ------------------ | ----------------------------------------------------------- |
| `base_url`         | Base URL for the [Maxim](/sdk/python/references/maxim) API. |
| `api_key`          | API key for authentication.                                 |
| `repository_id`    | ID of the repository to write logs to.                      |
| `auto_flush`       | Whether to automatically flush logs periodically.           |
| `flush_interval`   | Time interval in seconds between automatic flushes.         |
| `is_debug`         | Whether to enable debug logging.                            |
| `raise_exceptions` | Whether to raise exceptions or handle them silently.        |

#### \_\_init\_\_

```python theme={null}
def __init__(base_url,
             api_key,
             repository_id,
             auto_flush=True,
             flush_interval: Optional[int] = 10,
             is_debug=False,
             raise_exceptions=False)
```

Initialize a [LogWriterConfig](/sdk/python/references/logger/writer) instance.

**Arguments**:

| Name               | Description                                                 |
| ------------------ | ----------------------------------------------------------- |
| `base_url`         | Base URL for the [Maxim](/sdk/python/references/maxim) API. |
| `api_key`          | API key for authentication.                                 |
| `repository_id`    | ID of the repository to write logs to.                      |
| `auto_flush`       | Whether to automatically flush logs periodically.           |
| `flush_interval`   | Time interval in seconds between automatic flushes.         |
| `is_debug`         | Whether to enable debug logging.                            |
| `raise_exceptions` | Whether to raise exceptions or handle them silently.        |

## [LogWriter](/sdk/python/references/logger/writer)

```python theme={null}
class LogWriter()
```

Handles writing logs to the [Maxim](/sdk/python/references/maxim) API and local filesystem.

This class manages a queue of logs, periodically flushes them to the API,
and provides fallback to local filesystem storage when API calls fail.

#### \_\_init\_\_

```python theme={null}
def __init__(config: LogWriterConfig)
```

Initialize a [LogWriter](/sdk/python/references/logger/writer) instance.

**Arguments**:

| Name     | Description                                                              |
| -------- | ------------------------------------------------------------------------ |
| `config` | Configuration for the [LogWriter](/sdk/python/references/logger/writer). |

**Raises**:

* `ValueError` - If auto\_flush is enabled but flush\_interval is None.

#### repository\_id

```python theme={null}
@property
def repository_id()
```

Get the repository ID.

**Returns**:

| Name  | Description        |
| ----- | ------------------ |
| `str` | The repository ID. |

#### upload\_file\_data

```python theme={null}
def upload_file_data(add_attachment_log: CommitLog)
```

Upload a file attachment to the [Maxim](/sdk/python/references/maxim) API.

#### upload\_file

```python theme={null}
def upload_file(add_attachment_log: CommitLog)
```

Upload a file data attachment to the [Maxim](/sdk/python/references/maxim) API.

#### upload\_attachments

```python theme={null}
def upload_attachments(attachment_logs: list[CommitLog])
```

Upload all attachments to the [Maxim](/sdk/python/references/maxim) API.

#### upload\_attachment

```python theme={null}
def upload_attachment(add_attachment_log: CommitLog)
```

Upload an attachment to the [Maxim](/sdk/python/references/maxim) API.

**Arguments**:

| Name         | Description                  |
| ------------ | ---------------------------- |
| `attachment` | Attachment object to upload. |

#### is\_running\_on\_lambda

```python theme={null}
def is_running_on_lambda()
```

Check if the code is running in an AWS Lambda environment.

**Returns**:

| Name   | Description                                     |
| ------ | ----------------------------------------------- |
| `bool` | True if running in AWS Lambda, False otherwise. |

#### write\_to\_file

```python theme={null}
def write_to_file(logs)
```

Write logs to a local file.

**Arguments**:

| Name   | Description                                                                           |
| ------ | ------------------------------------------------------------------------------------- |
| `logs` | List of [CommitLog](/sdk/python/references/logger/components/types) objects to write. |

**Returns**:

str or None: Path to the file if successful, None otherwise.

**Raises**:

* `Exception` - If raise\_exceptions is True and writing fails.

#### flush\_log\_files

```python theme={null}
def flush_log_files()
```

Flush logs from files to the [Maxim](/sdk/python/references/maxim) API.

This method reads log files from the logs directory, sends them to the API,
and deletes the files if successful.

**Raises**:

* `Exception` - If raise\_exceptions is True and an error occurs.

#### can\_access\_filesystem

```python theme={null}
def can_access_filesystem()
```

Check if the filesystem is accessible for writing.

**Returns**:

| Name   | Description                                        |
| ------ | -------------------------------------------------- |
| `bool` | True if filesystem is accessible, False otherwise. |

#### flush\_logs

```python theme={null}
def flush_logs(logs: list[CommitLog])
```

Flush logs to the [Maxim](/sdk/python/references/maxim) API.

This method attempts to send logs to the API, with fallback mechanisms
for handling failures based on the environment.

**Arguments**:

| Name   | Description                                                                           |
| ------ | ------------------------------------------------------------------------------------- |
| `logs` | List of [CommitLog](/sdk/python/references/logger/components/types) objects to flush. |

#### commit

```python theme={null}
def commit(log: CommitLog)
```

Add a log to the queue for later flushing.

**Arguments**:

| Name  | Description                                                                             |
| ----- | --------------------------------------------------------------------------------------- |
| `log` | [CommitLog](/sdk/python/references/logger/components/types) object to add to the queue. |

**Raises**:

* `ValueError` - If the entity\_id is invalid and raise\_exceptions is True.

#### flush\_upload\_attachment\_logs

```python theme={null}
def flush_upload_attachment_logs(is_sync=False)
```

Flush all queued attachments to the [Maxim](/sdk/python/references/maxim) API.

This method empties the queue and sends all logs to the API,
with special handling for AWS Lambda environments.

#### flush\_commit\_logs

```python theme={null}
def flush_commit_logs(is_sync=False)
```

Flush all queued commit logs to the [Maxim](/sdk/python/references/maxim) API.

This method empties the queue and sends all logs to the API,
with special handling for AWS Lambda environments.

#### flush

```python theme={null}
def flush(is_sync=False)
```

Flush all queued logs to the [Maxim](/sdk/python/references/maxim) API.

#### cleanup

```python theme={null}
def cleanup(is_sync=False)
```

Clean up resources used by the [LogWriter](/sdk/python/references/logger/writer).

This method stops the flush thread, flushes any remaining logs,
and shuts down the executor.
