---
title: csv_logs
description: Log to local file system in yaml and CSV format.
canonical: >-
  https://lightning.ai/docs/pytorch/stable/optional-api/api/lightning.pytorch.loggers.csv_logs
---
# csv_logs {#csv-logs}

Classes

- [`CSVLogger`](#lightning.pytorch.loggers.csv_logs.CSVLogger) — Log to local file system in yaml and CSV format.
- [`ExperimentWriter`](#lightning.pytorch.loggers.csv_logs.ExperimentWriter) — Experiment writer for CSVLogger.

## CSV logger {#csv-logger}

CSV logger for basic experiment logging that does not require opening ports

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

Bases: [`Logger`](/docs/pytorch/2.6.6/optional-api/api/lightning.pytorch.loggers.logger.md#lightning.pytorch.loggers.logger.Logger "lightning.pytorch.loggers.logger.Logger"), [`CSVLogger`](/docs/fabric/stable/api/generated/lightning.fabric.loggers.CSVLogger#lightning.fabric.loggers.CSVLogger "(in lightning v2.7.0.dev)")

Log to local file system in yaml and CSV format.

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

Example

```python
>>> from lightning.pytorch import Trainer
>>> from lightning.pytorch.loggers import CSVLogger
>>> logger = CSVLogger("logs", name="my_exp_name")
>>> trainer = Trainer(logger=logger)
```

Parameters:

*   **save\_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)")\]) – Save directory
    
*   **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, optional. 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.
    
*   **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).
    

#### `log_hyperparams(params=None)` {#lightning.pytorch.loggers.csv_logs.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)"), [`None`](https://docs.python.org/3/builtins/constants.html#None "(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)")

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

Actual \_ExperimentWriter object. To use \_ExperimentWriter features in your [`LightningModule`](/docs/pytorch/2.6.6/optional-api/api/lightning.pytorch.core.LightningModule.md#lightning.pytorch.core.LightningModule "lightning.pytorch.core.LightningModule") do the following.

Example:

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

#### `property log_dir: str` {#lightning.pytorch.loggers.csv_logs.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 root_dir: str` {#lightning.pytorch.loggers.csv_logs.CSVLogger.root_dir}

Parent directory for all checkpoint subdirectories.

If the experiment name parameter is an empty string, no experiment subdirectory is used and the checkpoint will be saved in “save\_dir/version”

#### `property save_dir: str` {#lightning.pytorch.loggers.csv_logs.CSVLogger.save_dir}

The current directory where logs are saved.

Returns:

The path to current directory where logs are saved.

### `class lightning.pytorch.loggers.csv_logs.ExperimentWriter(log_dir)` {#lightning.pytorch.loggers.csv_logs.ExperimentWriter}

Bases: `_ExperimentWriter`

Experiment writer for CSVLogger.

Currently, supports to log hyperparameters and metrics in YAML and CSV format, respectively.

This logger supports logging to remote filesystems via `fsspec`. Make sure you have it installed.

Parameters:

**log\_dir** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)")) – Directory for the experiment logs

#### `log_hparams(params)` {#lightning.pytorch.loggers.csv_logs.ExperimentWriter.log_hparams}

Record hparams and save into files.

Return type:

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

---

**Navigation**

- Parent: [Api](/docs/pytorch/2.6.6/optional-api/api.md)
