From bc7cd2ccc24e476831039eea837fc3af48a6cf00 Mon Sep 17 00:00:00 2001 From: gabime Date: Sat, 30 Mar 2019 10:58:56 +0300 Subject: [PATCH] move lite namespace to topelevel spdlite --- lite-example/create_logger.cpp | 4 +-- lite-example/example.cpp | 4 +-- lite/spdlite.cpp | 62 +++++++++++++++++----------------- lite/spdlite.h | 53 ++++++++++++++--------------- 4 files changed, 61 insertions(+), 62 deletions(-) diff --git a/lite-example/create_logger.cpp b/lite-example/create_logger.cpp index 07608139..bc1b1a8e 100644 --- a/lite-example/create_logger.cpp +++ b/lite-example/create_logger.cpp @@ -6,7 +6,7 @@ #define UNUSED(x) (void)(x) // example of creating lite logger with console and file sink -spdlog::lite::logger spdlog::lite::create_logger(void *ctx) +spdlite::logger spdlite::create_logger(void *ctx) { UNUSED(ctx); std::shared_ptr logger_impl; @@ -19,5 +19,5 @@ spdlog::lite::logger spdlog::lite::create_logger(void *ctx) logger_impl = std::make_unique("my-logger", spdlog::sinks_init_list{console_sink, file_sink}); logger_impl->set_level(spdlog::level::debug); - return spdlog::lite::logger(std::move(logger_impl)); + return spdlite::logger(std::move(logger_impl)); } diff --git a/lite-example/example.cpp b/lite-example/example.cpp index 3668a400..5c945ecf 100644 --- a/lite-example/example.cpp +++ b/lite-example/example.cpp @@ -2,8 +2,8 @@ int main() { - auto l = spdlog::lite::create_logger(); - l.set_level(spdlog::lite::level::trace); + auto l = spdlite::create_logger(); + l.set_level(spdlite::level::trace); l.trace_printf("Hello %s ", "GABI"); l.info_printf("Hello %d", 12346); diff --git a/lite/spdlite.cpp b/lite/spdlite.cpp index f3557543..945e867d 100644 --- a/lite/spdlite.cpp +++ b/lite/spdlite.cpp @@ -1,34 +1,34 @@ #include "spdlite.h" #include "spdlog/spdlog.h" -static spdlog::level::level_enum to_spdlog_level(spdlog::lite::level level) +static spdlog::level::level_enum to_spdlog_level(spdlite::level level) { return static_cast(level); } -static spdlog::lite::level to_lite_level(spdlog::level::level_enum level) +static spdlite::level to_lite_level(spdlog::level::level_enum level) { - return static_cast(level); + return static_cast(level); } -spdlog::lite::logger::logger(std::shared_ptr impl) +spdlite::logger::logger(std::shared_ptr impl) { impl_ = std::move(impl); } -bool spdlog::lite::logger::should_log(spdlog::lite::level level) const SPDLOG_NOEXCEPT +bool spdlite::logger::should_log(spdlite::level level) const SPDLOG_NOEXCEPT { auto spd_level = to_spdlog_level(level); return impl_->should_log(spd_level); // TODO avoid the call using local level member? } -void spdlog::lite::logger::log(spdlog::lite::level lvl, const string_view_t &sv) +void spdlite::logger::log(spdlite::level lvl, const string_view_t &sv) { auto spd_level = to_spdlog_level(lvl); impl_->log(spd_level, sv); } -void spdlog::lite::logger::log_printf(spdlog::lite::level lvl, const char *format, va_list args) +void spdlite::logger::log_printf(spdlite::level lvl, const char *format, va_list args) { char buffer[500]; auto size = vsnprintf(buffer, sizeof(buffer), format, args); @@ -39,105 +39,105 @@ void spdlog::lite::logger::log_printf(spdlog::lite::level lvl, const char *forma log(lvl, string_view_t{buffer, static_cast(size)}); } -void spdlog::lite::logger::trace_printf(const char *format, ...) +void spdlite::logger::trace_printf(const char *format, ...) { va_list args; va_start(args, format); - log_printf(lite::level::trace, format, args); + log_printf(spdlite::level::trace, format, args); va_end(args); } -void spdlog::lite::logger::debug_printf(const char *format, ...) +void spdlite::logger::debug_printf(const char *format, ...) { va_list args; va_start(args, format); - log_printf(lite::level::debug, format, args); + log_printf(spdlite::level::debug, format, args); va_end(args); } -void spdlog::lite::logger::info_printf(const char *format, ...) +void spdlite::logger::info_printf(const char *format, ...) { va_list args; va_start(args, format); - log_printf(lite::level::info, format, args); + log_printf(spdlite::level::info, format, args); va_end(args); } -void spdlog::lite::logger::warn_printf(const char *format, ...) +void spdlite::logger::warn_printf(const char *format, ...) { va_list args; va_start(args, format); - log_printf(lite::level::warn, format, args); + log_printf(spdlite::level::warn, format, args); va_end(args); } -void spdlog::lite::logger::error_printf(const char *format, ...) +void spdlite::logger::error_printf(const char *format, ...) { va_list args; va_start(args, format); - log_printf(lite::level::err, format, args); + log_printf(spdlite::level::err, format, args); va_end(args); } -void spdlog::lite::logger::critical_printf(const char *format, ...) +void spdlite::logger::critical_printf(const char *format, ...) { va_list args; va_start(args, format); - log_printf(lite::level::critical, format, args); + log_printf(spdlite::level::critical, format, args); va_end(args); } -void spdlog::lite::logger::set_level(spdlog::lite::level level) noexcept +void spdlite::logger::set_level(spdlite::level level) noexcept { auto spd_level = to_spdlog_level(level); impl_->set_level(spd_level); } -spdlog::lite::level spdlog::lite::logger::level() const noexcept +spdlite::level spdlite::logger::level() const noexcept { return to_lite_level(impl_->level()); } -std::string spdlog::lite::logger::name() const noexcept +std::string spdlite::logger::name() const noexcept { return impl_->name(); } -void spdlog::lite::logger::flush() +void spdlite::logger::flush() { impl_->flush(); } -void spdlog::lite::logger::flush_on(spdlog::lite::level level) +void spdlite::logger::flush_on(spdlite::level level) { auto spd_level = to_spdlog_level(level); impl_->flush_on(spd_level); } -spdlog::lite::level spdlog::lite::logger::flush_level() const noexcept +spdlite::level spdlite::logger::flush_level() const noexcept { return to_lite_level(impl_->flush_level()); } // pattern -void spdlog::lite::logger::set_pattern(std::string pattern) noexcept +void spdlite::logger::set_pattern(std::string pattern) noexcept { impl_->set_pattern(std::move(pattern)); } -spdlog::lite::logger spdlog::lite::logger::clone(std::string logger_name) +spdlite::logger spdlite::logger::clone(std::string logger_name) { - return spdlog::lite::logger(impl_->clone(std::move(logger_name))); + return spdlite::logger(impl_->clone(std::move(logger_name))); } -void spdlog::lite::logger::log_formatted_(spdlog::lite::level lvl, const fmt::memory_buffer &formatted) +void spdlite::logger::log_formatted_(spdlite::level lvl, const fmt::memory_buffer &formatted) { auto spd_level = to_spdlog_level(lvl); impl_->log(spd_level, spdlog::details::fmt_helper::to_string_view(formatted)); } -spdlog::lite::logger &spdlog::lite::default_logger() +spdlite::logger &spdlite::default_logger() { - static spdlog::lite::logger s_default(spdlog::default_logger()); + static spdlite::logger s_default(spdlog::default_logger()); return s_default; } diff --git a/lite/spdlite.h b/lite/spdlite.h index 636dbdab..da4e589c 100644 --- a/lite/spdlite.h +++ b/lite/spdlite.h @@ -18,8 +18,8 @@ namespace spdlog { class logger; - -namespace lite { +} +namespace spdlite { // string_view type - either std::string_view or fmt::string_view (pre c++17) #if defined(FMT_USE_STD_STRING_VIEW) @@ -49,10 +49,10 @@ public: ~logger() = default; - bool should_log(lite::level lvl) const noexcept; + bool should_log(spdlite::level lvl) const noexcept; template - void log(lite::level lvl, const char *fmt, const Args &... args) + void log(spdlite::level lvl, const char *fmt, const Args &... args) { if (!should_log(lvl)) { @@ -64,23 +64,23 @@ public: } // log string view - void log(lite::level lvl, const string_view_t &sv); + void log(spdlite::level lvl, const string_view_t &sv); // log using printf format - void log_printf(lite::level lvl, const char *format, va_list args); + void log_printf(spdlite::level lvl, const char *format, va_list args); // // trace // void trace(const char *msg) { - log(lite::level::trace, string_view_t(msg)); + log(spdlite::level::trace, string_view_t(msg)); } template void trace(const char *fmt, const Args &... args) { - log(lite::level::trace, fmt, args...); + log(spdlite::level::trace, fmt, args...); } void trace_printf(const char *format, ...); @@ -90,13 +90,13 @@ public: // void debug(const char *msg) { - log(lite::level::debug, string_view_t(msg)); + log(spdlite::level::debug, string_view_t(msg)); } template void debug(const char *fmt, const Args &... args) { - log(lite::level::debug, fmt, args...); + log(spdlite::level::debug, fmt, args...); } void debug_printf(const char *format, ...); @@ -104,13 +104,13 @@ public: // info void info(const char *msg) { - log(lite::level::info, string_view_t(msg)); + log(spdlite::level::info, string_view_t(msg)); } template void info(const char *fmt, const Args &... args) { - log(lite::level::info, fmt, args...); + log(spdlite::level::info, fmt, args...); } void info_printf(const char *format, ...); @@ -118,13 +118,13 @@ public: // warn void warn(const char *msg) { - log(lite::level::warn, string_view_t(msg)); + log(spdlite::level::warn, string_view_t(msg)); } template void warn(const char *fmt, const Args &... args) { - log(lite::level::warn, fmt, args...); + log(spdlite::level::warn, fmt, args...); } void warn_printf(const char *format, ...); @@ -132,13 +132,13 @@ public: // error void error(const char *msg) { - log(lite::level::err, string_view_t(msg)); + log(spdlite::level::err, string_view_t(msg)); } template void error(const char *fmt, const Args &... args) { - log(lite::level::err, fmt, args...); + log(spdlite::level::err, fmt, args...); } void error_printf(const char *format, ...); @@ -146,37 +146,37 @@ public: // critical void critical(const char *msg) { - log(lite::level::critical, string_view_t(msg)); + log(spdlite::level::critical, string_view_t(msg)); } template void critical(const char *fmt, const Args &... args) { - log(lite::level::critical, fmt, args...); + log(spdlite::level::critical, fmt, args...); } void critical_printf(const char *format, ...); // setters/getters - void set_level(lite::level level) noexcept; + void set_level(spdlite::level level) noexcept; void set_pattern(std::string pattern) noexcept; - lite::level level() const noexcept; + spdlite::level level() const noexcept; std::string name() const noexcept; - lite::level flush_level() const noexcept; + spdlite::level flush_level() const noexcept; // flush void flush(); - void flush_on(lite::level log_level); + void flush_on(spdlite::level log_level); //clone with new name - spdlog::lite::logger clone(std::string logger_name); + spdlite::logger clone(std::string logger_name); protected: std::shared_ptr impl_; - void log_formatted_(lite::level lvl, const fmt::memory_buffer &formatted); + void log_formatted_(spdlite::level lvl, const fmt::memory_buffer &formatted); }; -spdlog::lite::logger &default_logger(); +spdlite::logger &default_logger(); template void trace(const char *fmt, const Args &... args) @@ -218,6 +218,5 @@ void critical(const char *fmt, const Args &... args) // implement it in a seperated and dedicated compilation unit for fast compiles. logger create_logger(void *ctx = nullptr); -} // namespace lite -} // namespace spdlog +} // namespace spdlite