# logging

## Class: ContinuousCSVLogger

```python
class ContinuousCSVLogger(CSVLogger):
```

### Description

`ContinuousCSVLogger` is a class that extends the `CSVLogger` from `pytorch_lightning.loggers`. It is used to continuously log metrics in a CSV file during model training.

### Inheritance

This class inherits from `CSVLogger` class in `pytorch_lightning.loggers`.

### Parameters

* `save_dir` (str): The directory where the CSV file will be saved.
* `name` (str, default="default"): The name of the CSV file.

### Methods

* `__init__(self, save_dir, name="default")`: Initializes the `ContinuousCSVLogger` object.
* `log_metrics(self, metrics, step=None)`: Logs the given metrics to the CSV file. If the CSV file doesn't exist, it creates a new one.

## Function: ck\_callback

```python
def ck_callback(checkpoint_dir: str) -> ModelCheckpoint:
```

### Description

The `ck_callback` function creates a `ModelCheckpoint` callback for use during training with `pytorch_lightning`. This callback automatically saves model checkpoints based on the specified monitoring metric.

### Parameters

* `checkpoint_dir` (str): The directory where model checkpoints will be saved.

### Returns

A `ModelCheckpoint` object configured to save the top 3 models with the lowest 'train\_loss' value.

### Example

Here's an example of how to use the `ck_callback` function:

```python
checkpoint_dir = "./model_checkpoints/"
checkpoint_callback = ck_callback(checkpoint_dir)
```

In this case, `checkpoint_callback` is a `ModelCheckpoint` object that can be used in the `pytorch_lightning` trainer for automatic model checkpointing:

```python
trainer = pl.Trainer(callbacks=[checkpoint_callback])
```

The trainer will then save the top 3 models with the lowest training loss in the specified directory.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://autossl.gitbook.io/autossl/api/utils/logging.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
