> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/holoscan/sdk-user-guide/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/holoscan/sdk-user-guide/_mcp/server.

# holoscan::DataLogger

> Pure virtual interface for data loggers.

Pure virtual interface for data loggers.

This interface defines the contract that all data loggers must implement for logging various types of data including generic std::any data, Tensors, and TensorMaps.

```cpp showLineNumbers={false}
#include <holoscan/data_logger.hpp>
```

---

## Constructors

### DataLogger \[#datalogger]

```cpp showLineNumbers={false}
holoscan::DataLogger::DataLogger() = default
```

### Destructor \[#destructor]

### \~DataLogger

```cpp showLineNumbers={false}
virtual holoscan::DataLogger::~DataLogger() = default
```

---

## Methods

### log\_data \[#logdata]

```cpp showLineNumbers={false}
virtual bool holoscan::DataLogger::log_data(
    const std::any &data,
    const std::string &unique_id,
    int64_t acquisition_timestamp = -1,
    const std::shared_ptr<MetadataDictionary> &metadata = nullptr,
    IOSpec::IOType io_type = IOSpec::IOType::kOutput,
    std::optional<cudaStream_t> stream = std::nullopt
)
```

Logs a message.

The unique\_id for the message will have the form:

* operator\_name.port\_name
* operator\_name.port\_name:index (for multi-receivers with N:1 connection)

For distributed applications, the fragment name will also appear in the unique id:

* fragment\_name.operator\_name.port\_name
* fragment\_name.operator\_name.port\_name:index

**Returns:** true if logging (including serialization and sending) was successful, false otherwise.

**Parameters**

**`data`** `const std::any &`

The data to log, passed as std::any.

---

**`unique_id`** `const std::string &`

A unique identifier for the message.

---

**`acquisition_timestamp`** `int64_t` — default: -1

Timestamp when the data was acquired (-1 if unknown).

---

**`metadata`** `const std::shared_ptr<MetadataDictionary> &` — default: nullptr

Associated metadata dictionary for the message.

---

**`io_type`** `IOSpec::IOType` — default: IOSpec::IOType::kOutput

The type of I/O port (kInput or kOutput).

---

**`stream`** `std::optional<cudaStream_t>` — default: std::nullopt

Optional CUDA stream for GPU operations.

---

### log\_tensor\_data \[#logtensordata]

```cpp showLineNumbers={false}
virtual bool holoscan::DataLogger::log_tensor_data(
    const std::shared_ptr<Tensor> &tensor,
    const std::string &unique_id,
    int64_t acquisition_timestamp = -1,
    const std::shared_ptr<MetadataDictionary> &metadata = nullptr,
    IOSpec::IOType io_type = IOSpec::IOType::kOutput,
    std::optional<cudaStream_t> stream = std::nullopt
)
```

Logs a [Tensor](tensor) with optional data content logging.

This specialized method allows efficient logging of tensor metadata without the overhead of logging large tensor data arrays when only header information is needed.

The unique\_id for the message will have the form:

* operator\_name.port\_name
* operator\_name.port\_name:index (for multi-receivers with N:1 connection)

For distributed applications, the fragment name will also appear in the unique id:

* fragment\_name.operator\_name.port\_name
* fragment\_name.operator\_name.port\_name:index

**Returns:** true if logging was successful, false otherwise.

**Parameters**

**`tensor`** `const std::shared_ptr<Tensor> &`

The [Tensor](tensor) to log.

---

**`unique_id`** `const std::string &`

A unique identifier for the message.

---

**`acquisition_timestamp`** `int64_t` — default: -1

Timestamp when the data was acquired (-1 if unknown).

---

**`metadata`** `const std::shared_ptr<MetadataDictionary> &` — default: nullptr

Associated metadata dictionary for the message.

---

**`io_type`** `IOSpec::IOType` — default: IOSpec::IOType::kOutput

The type of I/O port (kInput or kOutput).

---

**`stream`** `std::optional<cudaStream_t>` — default: std::nullopt

Optional CUDA stream for GPU operations.

---

### log\_tensormap\_data \[#logtensormapdata]

```cpp showLineNumbers={false}
virtual bool holoscan::DataLogger::log_tensormap_data(
    const TensorMap &tensor_map,
    const std::string &unique_id,
    int64_t acquisition_timestamp = -1,
    const std::shared_ptr<MetadataDictionary> &metadata = nullptr,
    IOSpec::IOType io_type = IOSpec::IOType::kOutput,
    std::optional<cudaStream_t> stream = std::nullopt
)
```

Logs a [TensorMap](tensormap) with optional data content logging.

This specialized method allows efficient logging of tensor map metadata without the overhead of logging large tensor data arrays when only header information is needed.

The unique\_id for the message will have the form:

* operator\_name.port\_name
* operator\_name.port\_name:index (for multi-receivers with N:1 connection)

For distributed applications, the fragment name will also appear in the unique id:

* fragment\_name.operator\_name.port\_name
* fragment\_name.operator\_name.port\_name:index

**Returns:** true if logging was successful, false otherwise.

**Parameters**

**`tensor_map`** `const TensorMap &`

The [TensorMap](tensormap) to log.

---

**`unique_id`** `const std::string &`

A unique identifier for the message.

---

**`acquisition_timestamp`** `int64_t` — default: -1

Timestamp when the data was acquired (-1 if unknown).

---

**`metadata`** `const std::shared_ptr<MetadataDictionary> &` — default: nullptr

Associated metadata dictionary for the message.

---

**`io_type`** `IOSpec::IOType` — default: IOSpec::IOType::kOutput

The type of I/O port (kInput or kOutput).

---

**`stream`** `std::optional<cudaStream_t>` — default: std::nullopt

Optional CUDA stream for GPU operations.

---

### log\_backend\_specific \[#logbackendspecific]

```cpp showLineNumbers={false}
virtual bool holoscan::DataLogger::log_backend_specific(
    const std::any &data,
    const std::string &unique_id,
    int64_t acquisition_timestamp = -1,
    const std::shared_ptr<MetadataDictionary> &metadata = nullptr,
    IOSpec::IOType io_type = IOSpec::IOType::kOutput,
    std::optional<cudaStream_t> stream = std::nullopt
)
```

Logs backend-specific data types.

This method is called for logging backend-specific data types (intended for use with backends that have separate emit/receive codepaths for backend-specific types). The data parameter is kept as std::any here to avoid making the base interface specific to a particular backend, but a backend-specific concrete implementation should be provided as needed via run-time type checking.

A concrete example of a backend-specific type is the GXF Entity type which is a heterogeneous collection of components. An implementation of this method for GXF entities is provided in the concrete implementation of the GXFConsoleLogger.

The unique\_id for the message will have the form:

* operator\_name.port\_name
* operator\_name.port\_name:index (for multi-receivers with N:1 connection)

For distributed applications, the fragment name will also appear in the unique id:

* fragment\_name.operator\_name.port\_name
* fragment\_name.operator\_name.port\_name:index

**Returns:** true if logging was successful, false if backend-specific logging is not supported.

**Parameters**

**`data`** `const std::any &`

The backend-specific data to log, passed as std::any.

---

**`unique_id`** `const std::string &`

A unique identifier for the message.

---

**`acquisition_timestamp`** `int64_t` — default: -1

Timestamp when the data was acquired (-1 if unknown).

---

**`metadata`** `const std::shared_ptr<MetadataDictionary> &` — default: nullptr

Associated metadata dictionary for the message.

---

**`io_type`** `IOSpec::IOType` — default: IOSpec::IOType::kOutput

The type of I/O port (kInput or kOutput).

---

**`stream`** `std::optional<cudaStream_t>` — default: std::nullopt

Optional CUDA stream for GPU operations.

---

### should\_log\_output \[#shouldlogoutput]

```cpp showLineNumbers={false}
virtual bool holoscan::DataLogger::should_log_output() const
```

Checks if the logger should log output ports.

If False, the data logger will not be applied during op\_output.emit() calls from [Operator::compute](gpuresidentoperator#compute).

**Returns:** true if the logger should log output ports, false otherwise.

### should\_log\_input \[#shouldloginput]

```cpp showLineNumbers={false}
virtual bool holoscan::DataLogger::should_log_input() const
```

Checks if the logger should log input ports.

If False, the data logger will not be applied during op\_input.receive() calls from [Operator::compute](gpuresidentoperator#compute).

**Returns:** true if the logger should log input ports, false otherwise.

### shutdown \[#shutdown]

```cpp showLineNumbers={false}
virtual void holoscan::DataLogger::shutdown()
```

Shutdown the data logger.

This method should be called to properly shutdown the data logger, including stopping any background threads and releasing resources. The default implementation does nothing. Data loggers that use background threads or other resources should override this method to perform proper cleanup.