Logging

    March 30, 2025
    + 12

    The Couchbase C++ SDK allows logging to be configured programmatically. Internally, the SDK uses the spdlog logging library.

    Once the logger has been initialized, The default log level is info.

    The following log levels are supported (in order of increasing amount of information logged):

    1. off

    2. critical

    3. error

    4. warning

    5. info

    6. debug

    7. trace

    The C++ SDK can be configured to send logs to standard output, or to a file. The logger can be initialized and logging level changed like so:

    #import <couchbase/logger.hxx>
    
    void
    initialize_logger()
    {
        // Initialize logging to standard output
        couchbase::logger::initialize_console_logger();
    
        // Initialize logging to a file
        couchbase::logger::initialize_file_logger("/path/to/file");
    
        // Set log level
        couchbase::logger::set_level(couchbase::logger::log_level::warn);
    }