| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- //
- // 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 {
- 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:
- friend class manager;
- 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&);
-
- private:
- std::string logger_name_;
- std::shared_ptr<logger_impl> impl_;
- };
- }
- #undef VA_LOG
- #undef LA_LOGN
|