.. _program_listing_file_eshet_log.hpp: Program Listing for File log.hpp ================================ |exhale_lsh| :ref:`Return to documentation for file ` (``eshet/log.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp #pragma once #include #include #include namespace eshet { struct LogCallbacks { virtual void debug(const std::string &s) { fprintf(stderr, "eshet: %s\n", s.c_str()); } virtual void error(const std::string &s) { fprintf(stderr, "eshet: %s\n", s.c_str()); } virtual ~LogCallbacks() {} }; class Logger { public: void set_log_callbacks(std::shared_ptr new_log_callbacks) { std::lock_guard guard(callbacks_mut); log_callbacks = new_log_callbacks; } void debug(const std::string &s) { std::lock_guard guard(callbacks_mut); log_callbacks->debug(s); } void error(const std::string &s) { std::lock_guard guard(callbacks_mut); log_callbacks->error(s); } private: std::mutex callbacks_mut; std::shared_ptr log_callbacks = std::make_shared(); }; } // namespace eshet