.. _program_listing_file_include_dx2_logging.hpp: Program Listing for File logging.hpp ==================================== |exhale_lsh| :ref:`Return to documentation for file ` (``include/dx2/logging.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp #pragma once #include #include #include #include namespace dx2_log { // Returns true if DX2_DEBUG is set inline bool is_debug_enabled() { return std::getenv("DX2_DEBUG") != nullptr; } inline void info(std::string_view msg) { fmt::print(fg(fmt::color::green) | fmt::emphasis::bold, "[INFO] "); fmt::print("{}\n", msg); } inline void warning(std::string_view msg) { fmt::print(stderr, fg(fmt::color::yellow) | fmt::emphasis::bold, "[WARNING] "); fmt::print(stderr, "{}\n", msg); } inline void error(std::string_view msg) { fmt::print(stderr, fg(fmt::color::red) | fmt::emphasis::bold, "[ERROR] "); fmt::print(stderr, "{}\n", msg); } inline void debug(std::string_view msg) { if (is_debug_enabled()) { fmt::print(fg(fmt::color::blue) | fmt::emphasis::bold, "[DEBUG] "); fmt::print("{}\n", msg); } } // Optionally, overloads that support format-style args: template inline void debug(fmt::format_string fmt_str, Args &&...args) { if (is_debug_enabled()) { fmt::print(fg(fmt::color::blue) | fmt::emphasis::bold, "[DEBUG] "); fmt::print(fmt_str, std::forward(args)...); fmt::print("\n"); } } } // namespace dx2_log