---
title: CSVLogger
description: Log to the local file system in CSV format.
canonical: >-
  https://lightning.ai/docs/fabric/stable/full-api-reference/api/generated/lightning.fabric.loggers.CSVLogger
---
# CSVLogger {#csvlogger}

### `class lightning.fabric.loggers.CSVLogger(root_dir, name='lightning_logs', version=None, prefix='', flush_logs_every_n_steps=100)` {#lightning.fabric.loggers.CSVLogger}

Bases: [`Logger`](/docs/fabric/2.6.6/full-api-reference/api/generated/lightning.fabric.loggers.Logger.md#lightning.fabric.loggers.Logger "lightning.fabric.loggers.logger.Logger")

Log to the local file system in CSV format.

Logs are saved to `os.path.join(root_dir, name, version)`.

Parameters:

*   **root\_dir** (`Union`\[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"), [`Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path "(in Python v3.15)")\]) – The root directory in which all your experiments with different names and versions will be stored.
    
*   **name** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.15)")\[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)")\]) – Experiment name. Defaults to `'lightning_logs'`. If name is `None`, logs (versions) will be stored to the save dir directly.
    
*   **version** (`Union`\[[`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)"), [`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"), [`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")\]) – Experiment version. If version is not specified the logger inspects the save directory for existing versions, then automatically assigns the next available version. If the version is specified, and the directory already contains a metrics file for that version, it will be overwritten.
    
*   **prefix** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)")) – A string to put at the beginning of metric keys.
    
*   **flush\_logs\_every\_n\_steps** ([`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)")) – How often to flush logs to disk (defaults to every 100 steps).
    

Example:

```python
from lightning.fabric.loggers import CSVLogger

logger = CSVLogger("path/to/logs/root", name="my_model")
logger.log_metrics({"loss": 0.235, "acc": 0.75})
logger.finalize("success")
```

#### `finalize(status)` {#lightning.fabric.loggers.CSVLogger.finalize}

Do any processing that is necessary to finalize an experiment.

Parameters:

**status** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)")) – Status that the experiment finished with (e.g. success, failed, aborted)

Return type:

[`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")

#### `log_hyperparams(params)` {#lightning.fabric.loggers.CSVLogger.log_hyperparams}

Record hyperparameters.

Parameters:

*   **params** (`Union`\[[`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict "(in Python v3.15)")\[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"), [`Any`](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.15)")\], [`Namespace`](https://docs.python.org/3/library/argparse.html#argparse.Namespace "(in Python v3.15)")\]) – [`Namespace`](https://docs.python.org/3/library/argparse.html#argparse.Namespace "(in Python v3.15)") or Dict containing the hyperparameters
    
*   **args** – Optional positional arguments, depends on the specific logger being used
    
*   **kwargs** – Optional keyword arguments, depends on the specific logger being used
    

Return type:

[`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")

#### `log_metrics(metrics, step=None)` {#lightning.fabric.loggers.CSVLogger.log_metrics}

Records metrics. This method logs metrics as soon as it received them.

Parameters:

*   **metrics** ([`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict "(in Python v3.15)")\[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"), `Union`\[[`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)"), [`float`](https://docs.python.org/3/builtins/functions.html#float "(in Python v3.15)")\]\]) – Dictionary with metric names as keys and measured quantities as values
    
*   **step** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.15)")\[[`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)")\]) – Step number at which the metrics should be recorded
    

Return type:

[`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")

#### `save()` {#lightning.fabric.loggers.CSVLogger.save}

Save log data.

Return type:

[`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")

#### `property experiment: _ExperimentWriter` {#lightning.fabric.loggers.CSVLogger.experiment}

Actual ExperimentWriter object. To use ExperimentWriter features anywhere in your code, do the following.

Example:

```python
self.logger.experiment.some_experiment_writer_function()
```

#### `property log_dir: str` {#lightning.fabric.loggers.CSVLogger.log_dir}

The log directory for this run.

By default, it is named `'version_${self.version}'` but it can be overridden by passing a string value for the constructor’s version parameter instead of `None` or an int.

#### `property name: str` {#lightning.fabric.loggers.CSVLogger.name}

Gets the name of the experiment.

Returns:

The name of the experiment.

#### `property root_dir: str` {#lightning.fabric.loggers.CSVLogger.root_dir}

Gets the save directory where the versioned CSV experiments are saved.

#### `property version: Union[int, str]` {#lightning.fabric.loggers.CSVLogger.version}

Gets the version of the experiment.

Returns:

The version of the experiment if it is specified, else the next version.

---

**Navigation**

- Parent: [Generated](/docs/fabric/2.6.6/full-api-reference/api/generated.md)
