Skip to content
Takatoshi Kondo edited this page Aug 20, 2020 · 6 revisions

Logging

mqtt_cpp outputs log messages using Boost.Log.

Setup

By default, mqtt_cpp use the default Boost.Log settings. Custom setup is usually convenient.

Typical setup

mqtt_cpp provides a typical logging setting.

First, include the following file:

#include <mqtt/setup_log.hpp>

Next, call setup_log().

int main() {
    ...

    mqtt::setup_log(
        {
            { "mqtt_api", mqtt::severity_level::trace },
            { "mqtt_cb", mqtt::severity_level::debug },
        }
    );

    ...

The setup takes std::map<mqtt::channel, mqtt::severity_level>. You can set the threshold severity_level by each channel.

You can also call setup_log() like as follows:

int main() {
    ...

    mqtt::setup_log(
        mqtt::severity_level::warning
    );

    ...

The threshold is applied for all channels.

channel

Channel describes what kind of message.

channel description
mqtt_api API is called
mqtt_cb event is occurred

severity

High priority                Low priority
fatal, error, warning, info, debug, trace
Clone this wiki locally