# 9.7. Consumers¶

Consumers are classes that take a Log::Entry and produce a log output accordingly. eProsima Fast DDS provides three different log consumers that output log entries to different streams:

## 9.7.1. StdoutConsumer¶

StdoutConsumer outputs log entries to STDOUT stream following the convection specified in Log Entry Specification. It is the default and only log consumer of the logging module if the CMake option LOG_CONSUMER_DEFAULT is set to AUTO, STDOUT, or not set at all. It can be registered and unregistered using the methods explained in Register Consumers and Reset Configuration.

// Create a StdoutConsumer consumer that logs entries to stdout stream.
std::unique_ptr<StdoutConsumer> stdout_consumer(new StdoutConsumer());

// Register the consumer.
Log::RegisterConsumer(std::move(stdout_consumer));


## 9.7.2. StdoutErrConsumer¶

StdoutErrConsumer uses a Log::Kind threshold to filter the output of the log entries. Those log entries whose Log::Kind is equal to or more severe than the given threshold output to STDERR. Other log entries output to STDOUT. By default, the threshold is set to Log::Kind::Warning. StdoutErrConsumer::stderr_threshold() allows the user to modify the default threshold.

Additionally, if CMake option LOG_CONSUMER_DEFAULT is set to STDOUTERR, the logging module will use this consumer as the default log consumer.

// Create a StdoutErrConsumer consumer that logs entries to stderr only when the Log::Kind is equal to ERROR
std::unique_ptr<StdoutErrConsumer> stdouterr_consumer(new StdoutErrConsumer());
stdouterr_consumer->stderr_threshold(Log::Kind::Error);

// Register the consumer
Log::RegisterConsumer(std::move(stdouterr_consumer));


## 9.7.3. FileConsumer¶

FileConsumer provides the logging module with log-to-file logging capabilities. Applications willing to hold a persistent execution log record can specify a logging file using this consumer. Furthermore, the application can choose whether the file stream should be in “write” or “append” mode, according to the behaviour defined by std::fstream::open().

// Create a FileConsumer consumer that logs entries in "archive_1.log", opening the file in "write" mode.
std::unique_ptr<FileConsumer> write_file_consumer(new FileConsumer("archive_1.log", false));

// Create a FileConsumer consumer that logs entries in "archive_2.log", opening the file in "append" mode.
std::unique_ptr<FileConsumer> append_file_consumer(new FileConsumer("archive_2.log", true));

// Register the consumers.
Log::RegisterConsumer(std::move(write_file_consumer));
Log::RegisterConsumer(std::move(append_file_consumer));