| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- //
- // c_logger.hpp
- // logging
- //
- // Created by Sam Jaffe on 4/1/19.
- //
- #pragma once
- #include <cstdarg>
- #include <cstdlib>
- #include <cstring>
- #include <memory>
- #include <string>
- #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<logger_impl> 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 <typename... Args>
- 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<logger_impl> impl);
- private:
- void vlognf(level, size_t, char const *, va_list);
- void log(level, std::string const &);
- };
- }
- #undef VA_LOG
- #undef LA_LOGN
|