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

# autogen.logger.base_logger.BaseLogger

<h2 id="autogen.logger.base_logger.BaseLogger" class="doc doc-heading">
  <code class="doc-symbol doc-symbol-heading doc-symbol-class" />

  <span class="doc doc-object-name doc-class-name">BaseLogger</span>
</h2>

```python theme={null}
BaseLogger()
```

Helper class that provides a standard way to create an ABC using
inheritance.

### Instance Methods

<code class="doc-symbol doc-symbol-heading doc-symbol-method" />

#### get\_connection

```python theme={null}
get_connection(self) -> None | Connection
```

Return a connection to the logging database.

<br />

<code class="doc-symbol doc-symbol-heading doc-symbol-method" />

#### log\_chat\_completion

```python theme={null}
log_chat_completion(
    self,
    invocation_id: UUID,
    client_id: int,
    wrapper_id: int,
    source: str | Agent,
    request: dict[str, float | str | list[dict[str, str]]],
    response: str | ChatCompletion,
    is_cached: int,
    cost: float,
    start_time: str
) -> None
```

Log a chat completion to database.<br />In AG2, chat completions are somewhat complicated because they are handled by the `autogen.oai.OpenAIWrapper` class.<br />One invocation to `create` can lead to multiple underlying OpenAI calls, depending on the llm\_config list used, and
any errors or retries.<br />

<b>Parameters:</b>

| Name            | Description                                                                                                                                         |
| --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
| `invocation_id` | A unique identifier for the invocation to the OpenAIWrapper.create method call<br /><br />**Type:** uuid.UUID                                       |
| `client_id`     | A unique identifier for the underlying OpenAI client instance<br /><br />**Type:** int                                                              |
| `wrapper_id`    | A unique identifier for the OpenAIWrapper instance<br /><br />**Type:** int                                                                         |
| `source`        | The source/creator of the event as a string name or an Agent instance<br /><br />**Type:** str \| Agent                                             |
| `request`       | A dictionary representing the request or call to the OpenAI client endpoint<br /><br />**Type:** dict\[str, float \| str \| list\[dict\[str, str]]] |
| `response`      | The response from OpenAI<br /><br />**Type:** str \| ChatCompletion                                                                                 |
| `is_cached`     | 1 if the response was a cache hit, 0 otherwise<br /><br />**Type:** int                                                                             |
| `cost`          | The cost for OpenAI response<br /><br />**Type:** float                                                                                             |
| `start_time`    | A string representing the moment the request was initiated<br /><br />**Type:** str                                                                 |

<br />

<code class="doc-symbol doc-symbol-heading doc-symbol-method" />

#### log\_event

```python theme={null}
log_event(
    self,
    source: str | Agent,
    name: str,
    **kwargs: dict[str, Any]
) -> None
```

Log an event for an agent.<br />

<b>Parameters:</b>

| Name       | Description                                                                                             |
| ---------- | ------------------------------------------------------------------------------------------------------- |
| `source`   | The source/creator of the event as a string name or an Agent instance<br /><br />**Type:** str \| Agent |
| `name`     | The name of the event<br /><br />**Type:** str                                                          |
| `**kwargs` | **Type:** dict\[str, Any]                                                                               |

<br />

<code class="doc-symbol doc-symbol-heading doc-symbol-method" />

#### log\_function\_use

```python theme={null}
log_function_use(
    self,
    source: str | Agent,
    function: F,
    args: dict[str, Any],
    returns: Any
) -> None
```

Log the use of a registered function (could be a tool)

<b>Parameters:</b>

| Name       | Description                                                                                             |
| ---------- | ------------------------------------------------------------------------------------------------------- |
| `source`   | The source/creator of the event as a string name or an Agent instance<br /><br />**Type:** str \| Agent |
| `function` | The function information<br /><br />**Type:** F                                                         |
| `args`     | The function args to log<br /><br />**Type:** dict\[str, Any]                                           |
| `returns`  | The return<br /><br />**Type:** Any                                                                     |

<br />

<code class="doc-symbol doc-symbol-heading doc-symbol-method" />

#### log\_new\_agent

```python theme={null}
log_new_agent(
    self,
    agent: ConversableAgent,
    init_args: dict[str, Any]
) -> None
```

Log the birth of a new agent.<br />

<b>Parameters:</b>

| Name        | Description                                                                                      |
| ----------- | ------------------------------------------------------------------------------------------------ |
| `agent`     | The agent to log.<br /><br />**Type:** ConversableAgent                                          |
| `init_args` | The arguments passed to the construct the conversable agent<br /><br />**Type:** dict\[str, Any] |

<br />

<code class="doc-symbol doc-symbol-heading doc-symbol-method" />

#### log\_new\_client

```python theme={null}
log_new_client(
    self,
    client: AzureOpenAI | OpenAI,
    wrapper: OpenAIWrapper,
    init_args: dict[str, Any]
) -> None
```

Log the birth of a new OpenAIWrapper.<br />

<b>Parameters:</b>

| Name        | Description                                                                            |
| ----------- | -------------------------------------------------------------------------------------- |
| `client`    | The client to log.<br /><br />**Type:** AzureOpenAI \| OpenAI                          |
| `wrapper`   | The wrapper that created the client.<br /><br />**Type:** OpenAIWrapper                |
| `init_args` | The arguments passed to the construct the client.<br /><br />**Type:** dict\[str, Any] |

<br />

<code class="doc-symbol doc-symbol-heading doc-symbol-method" />

#### log\_new\_wrapper

```python theme={null}
log_new_wrapper(
    self,
    wrapper: OpenAIWrapper,
    init_args: dict[str, LLMConfig | list[LLMConfig]]
) -> None
```

Log the birth of a new OpenAIWrapper.<br />

<b>Parameters:</b>

| Name        | Description                                                                                                      |
| ----------- | ---------------------------------------------------------------------------------------------------------------- |
| `wrapper`   | The wrapper to log.<br /><br />**Type:** OpenAIWrapper                                                           |
| `init_args` | The arguments passed to the construct the wrapper<br /><br />**Type:** dict\[str, LLMConfig \| list\[LLMConfig]] |

<br />

<code class="doc-symbol doc-symbol-heading doc-symbol-method" />

#### start

```python theme={null}
start(self) -> str
```

Open a connection to the logging database, and start recording.<br />Returns: <br />    session\_id (str):     a unique id for the logging session

<b>Returns:</b>

| Type | Description                                            |
| ---- | ------------------------------------------------------ |
| str  | session\_id (str): a unique id for the logging session |

<br />

<code class="doc-symbol doc-symbol-heading doc-symbol-method" />

#### stop

```python theme={null}
stop(self) -> None
```

Close the connection to the logging database, and stop logging.

<br />
