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

### `class lightning.fabric.loggers.TensorBoardLogger(root_dir, name='lightning_logs', version=None, default_hp_metric=True, prefix='', sub_dir=None, **kwargs)` {#lightning.fabric.loggers.TensorBoardLogger}

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 local file system in [TensorBoard](https://www.tensorflow.org/tensorboard) format.

Implemented using `SummaryWriter`. Logs are saved to `os.path.join(root_dir, name, version)`. This is the recommended logger in Lightning Fabric.

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 it is the empty string then no per-experiment subdirectory is used.
    
*   **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 it is a string then it is used as the run-specific subdirectory name, otherwise `'version_${version}'` is used.
    
*   **default\_hp\_metric** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – Enables a placeholder metric with key hp\_metric when log\_hyperparams is called without a metric (otherwise calls to `log_hyperparams` without a metric are ignored).
    
*   **prefix** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)")) – A string to put at the beginning of all metric keys.
    
*   **sub\_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)"), [`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")\]) – Sub-directory to group TensorBoard logs. If a `sub_dir` argument is passed then logs are saved in `/root_dir/name/version/sub_dir/`. Defaults to `None` in which case logs are saved in `/root_dir/name/version/`.
    
*   **\*\*kwargs** ([`Any`](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.15)")) – Additional arguments used by `tensorboardX.SummaryWriter` can be passed as keyword arguments in this logger. To automatically flush to disk, max\_queue sets the size of the queue for pending logs before flushing. flush\_secs determines how many seconds elapses before flushing.
    

Example:

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

logger = TensorBoardLogger("path/to/logs/root", name="my_model")
logger.log_hyperparams({"epochs": 5, "optimizer": "Adam"})
logger.log_metrics({"acc": 0.75})
logger.finalize("success")
```

#### `finalize(status)` {#lightning.fabric.loggers.TensorBoardLogger.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_graph(model, input_array=None)` {#lightning.fabric.loggers.TensorBoardLogger.log_graph}

Record model graph.

Parameters:

*   **model** ([`Module`](https://docs.pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module "(in PyTorch v2.15)")) – the model with an implementation of `forward`.
    
*   **input\_array** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.15)")\[[`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")\]) – input passes to model.forward
    

Return type:

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

#### `log_hyperparams(params, metrics=None, step=None)` {#lightning.fabric.loggers.TensorBoardLogger.log_hyperparams}

Record hyperparameters. TensorBoard logs with and without saved hyperparameters are incompatible, the hyperparameters are then not displayed in the TensorBoard. Please delete or move the previously saved logs to display the new ones with 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)")\]) – A dictionary-like container with the hyperparameters
    
*   **metrics** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.15)")\[[`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)")\]\]) – 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)")\]) – Optional global step number for the logged metrics
    

Return type:

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

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

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

Parameters:

*   **metrics** ([`Mapping`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping "(in Python v3.15)")\[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.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.TensorBoardLogger.save}

Save log data.

Return type:

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

#### `property experiment: SummaryWriter` {#lightning.fabric.loggers.TensorBoardLogger.experiment}

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

Example:

```python
logger.experiment.some_tensorboard_function()
```

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

The directory for this run’s tensorboard checkpoint.

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.TensorBoardLogger.name}

Get the name of the experiment.

Returns:

The name of the experiment.

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

Gets the save directory where the TensorBoard experiments are saved.

Returns:

The local path to the save directory where the TensorBoard experiments are saved.

#### `property sub_dir: Optional[str]` {#lightning.fabric.loggers.TensorBoardLogger.sub_dir}

Gets the sub directory where the TensorBoard experiments are saved.

Returns:

The local path to the sub directory where the TensorBoard experiments are saved.

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

Get the experiment version.

Returns:

The experiment version if specified else the next version.

---

**Navigation**

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