// // c_logger.hpp // logging // // Created by Sam Jaffe on 4/1/19. // #pragma once #include #include #include #include #include #include "level.h" #define VA_LOGN(level, size) \ do { \ va_list vargs; \ va_start(vargs, fmt); \ vlognf(level, size, fmt, vargs); \ va_end(vargs); \ } while (0) #define VA_LOG(level) VA_LOGN(level, c_logger::LOGF_MAX_SIZE) #define MAKE_LOGGER_FMT(lvl) \ inline void lvl##f(char const * fmt, ...) { VA_LOG(level::lvl); } \ inline void lvl##nf(size_t n, char const * fmt, ...) { \ VA_LOGN(level::lvl, n); \ } \ inline void lvl(char const * msg) { log(level::lvl, msg); } \ inline void lvl(std::string const & msg) { log(level::lvl, msg); } namespace logging { enum class level : int; class logger_impl; class c_logger { private: friend class manager; std::string logger_name_; std::shared_ptr impl_; public: static const size_t LOGF_MAX_SIZE = 2048; public: MAKE_LOGGER_FMT(trace) MAKE_LOGGER_FMT(debug) MAKE_LOGGER_FMT(info) MAKE_LOGGER_FMT(warn) MAKE_LOGGER_FMT(error) MAKE_LOGGER_FMT(critical) MAKE_LOGGER_FMT(fatal) template inline void log(level ll, std::string const & interp, Args &&... args); void flush(); ~c_logger(); protected: c_logger(std::string const & name, std::shared_ptr impl); private: void vlognf(level, size_t, char const *, va_list); void log(level, std::string const &); }; } #undef VA_LOG #undef LA_LOGN