From 509a503761e8f108f452cdf04416222071fd579f Mon Sep 17 00:00:00 2001 From: gabime Date: Sun, 24 Mar 2019 01:18:05 +0200 Subject: [PATCH] update example --- lite-example/create_lite.cpp | 23 ++++++++++++-------- lite-example/example.cpp | 2 +- lite/spdlite.h | 42 ++++++++++++++++++++---------------- 3 files changed, 38 insertions(+), 29 deletions(-) diff --git a/lite-example/create_lite.cpp b/lite-example/create_lite.cpp index 1a6d6bfe..74892d64 100644 --- a/lite-example/create_lite.cpp +++ b/lite-example/create_lite.cpp @@ -3,16 +3,21 @@ #include "spdlog/sinks/basic_file_sink.h" #include "spdlog/sinks/stdout_color_sinks.h" +#define UNUSED(x) (void)(x) + +// example of creating lite logger with console and file sink spdlog::lite::logger spdlog::create_lite(void *ctx) { - if (ctx) - { - //.. - } - auto logger_impl = spdlog::stdout_color_mt("mylogger"); - auto file_sink = std::make_shared("file.txt", true); - file_sink->set_level(spdlog::level::info); - logger_impl->sinks().push_back(file_sink); - logger_impl->set_level(spdlog::level::trace); + UNUSED(ctx); + std::shared_ptr logger_impl; + + auto console_sink = std::make_shared (); + console_sink->set_level(spdlog::level::debug); + + auto file_sink = std::make_shared ("log.txt", true); + file_sink ->set_level(spdlog::level::info); + + logger_impl = std::make_shared("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)); } diff --git a/lite-example/example.cpp b/lite-example/example.cpp index e4185131..bffd0a2f 100644 --- a/lite-example/example.cpp +++ b/lite-example/example.cpp @@ -2,7 +2,7 @@ int main() { - auto l = spdlog::create_lite(); + auto l = spdlog::create_lite((void*)"async"); l.set_level(spdlog::lite::level::trace); l.trace_f("Hello %s ", "GABI"); diff --git a/lite/spdlite.h b/lite/spdlite.h index ddfc4b27..4429b50d 100644 --- a/lite/spdlite.h +++ b/lite/spdlite.h @@ -43,10 +43,10 @@ public: ~logger() = default; - bool should_log(spdlog::lite::level lvl) const noexcept; + bool should_log(lite::level lvl) const noexcept; template - void log(spdlog::lite::level lvl, const char *fmt, const Args &... args) + void log(lite::level lvl, const char *fmt, const Args &... args) { if (!should_log(lvl)) { @@ -58,21 +58,21 @@ public: } // log string view - void log(spdlog::lite::level lvl, const string_view_t &sv); - void log_printf(spdlog::lite::level lvl, const char *format, va_list args); + void log(lite::level lvl, const string_view_t &sv); + void log_printf(lite::level lvl, const char *format, va_list args); // // trace // void trace(const char *msg) { - log(spdlog::lite::level::trace, string_view_t(msg)); + log(lite::level::trace, string_view_t(msg)); } template void trace(const char *fmt, const Args &... args) { - log(spdlog::lite::level::trace, fmt, args...); + log(lite::level::trace, fmt, args...); } void trace_f(const char *printf_format, ...); @@ -82,13 +82,13 @@ public: // void debug(const char *msg) { - log(spdlog::lite::level::debug, string_view_t(msg)); + log(lite::level::debug, string_view_t(msg)); } template void debug(const char *fmt, const Args &... args) { - log(spdlog::lite::level::debug, fmt, args...); + log(lite::level::debug, fmt, args...); } void debug_f(const char *printf_format, ...); @@ -98,13 +98,13 @@ public: // void info(const char *msg) { - log(spdlog::lite::level::info, string_view_t(msg)); + log(lite::level::info, string_view_t(msg)); } template void info(const char *fmt, const Args &... args) { - log(spdlog::lite::level::info, fmt, args...); + log(lite::level::info, fmt, args...); } void info_f(const char *printf_format, ...); @@ -114,13 +114,13 @@ public: // void warn(const char *msg) { - log(spdlog::lite::level::warn, string_view_t(msg)); + log(lite::level::warn, string_view_t(msg)); } template void warn(const char *fmt, const Args &... args) { - log(spdlog::lite::level::warn, fmt, args...); + log(lite::level::warn, fmt, args...); } void warn_f(const char *printf_format, ...); @@ -130,13 +130,13 @@ public: // void error(const char *msg) { - log(spdlog::lite::level::err, string_view_t(msg)); + log(lite::level::err, string_view_t(msg)); } template void error(const char *fmt, const Args &... args) { - log(spdlog::lite::level::err, fmt, args...); + log(lite::level::err, fmt, args...); } void error_f(const char *printf_format, ...); @@ -146,13 +146,13 @@ public: // void critical(const char *msg) { - log(spdlog::lite::level::critical, string_view_t(msg)); + log(lite::level::critical, string_view_t(msg)); } template void critical(const char *fmt, const Args &... args) { - log(spdlog::lite::level::critical, fmt, args...); + log(lite::level::critical, fmt, args...); } void critical_f(const char *printf_format, ...); @@ -168,13 +168,17 @@ public: // flush // void flush(); - void flush_on(spdlog::lite::level log_level); - spdlog::lite::level flush_level() const; + void flush_on(lite::level log_level); + lite::level flush_level() const; + + // + // set pattern + // void set_pattern(std::string pattern); protected: std::shared_ptr impl_; - void log_formatted_(spdlog::lite::level lvl, const fmt::memory_buffer &formatted); + void log_formatted_(lite::level lvl, const fmt::memory_buffer &formatted); }; spdlog::lite::logger &default_logger();