logging#

The cryptomatte-api uses spdlog as a logging library and adapter. We expose functions to either register your own logger with it or get the logger used by the cryptomatte-api.

Internally we will call cmatte::get_logger to retrieve the logging object so this set up can be done at any time and any subsequent calls will use the new logger.

Below you can find an example of setting up your own logger to use with the cryptomatte-api:

#include <cryptomatte/cryptomatte.h>
#include <cryptomatte/logger.h>


auto main() -> int
{
        std::shared_ptr<spdlog::logger> my_logger = ...;
        cmatte::set_logger(my_logger);

        // Now call any functions you wish and they will log to your logger instead.
        cmatte::cryptomatte::load(...);
};

If you wish to instead modify the existing logger to change the verbosity etc. you can also do this via:

#include <cryptomatte/cryptomatte.h>
#include <cryptomatte/logger.h>


auto main() -> int
{
        auto cmatte_logger = cmatte::get_logger();
        cmatte_logger->set_level(spdlog::level::debug);
};

logging function reference#

static std::string cmatte::s_default_logger_name = "cryptomatte_api"#

The default logger name used internally if the user does not provide one.

void cmatte::set_logger(std::shared_ptr<spdlog::logger> logger)#

Set the logger instance used by the cryptomatte-api.

This function allows consumers of the library to provide their own spdlog::logger instance. This can be useful to integrate the library’s logging output into an existing logging system, route messages to a file, or change verbosity dynamically.

If no logger is set, the library will lazily create a default one that logs to stdout at warning level.

Parameters:

logger – The spdlog::logger instance to use for all library logging.

std::shared_ptr<spdlog::logger> cmatte::get_logger()#

Retrieve the current logger instance used by the cryptomatte-api.

If no logger has been previously set via set_logger, this function will initialize a default logger named "cryptomatte_api" that logs to standard output with color support, and at spdlog::level::warn verbosity.

Returns:

A shared pointer to the currently active spdlog::logger.