diff --git a/README.md b/README.md index c1a74489..f5e5fe34 100644 --- a/README.md +++ b/README.md @@ -149,13 +149,13 @@ int main(int, char*[]) err_handler_example(); // Apply a function on all registered loggers - spd::apply_all([&](std::shared_ptr l) + spd::apply_all([&](std::shared_ptr l) { l->info("End of example."); }); // Release and close all loggers - spd::drop_all(); + spdlog::drop_all(); } // Exceptions will only be thrown upon failed logger or sink construction (not during logging) catch (const spd::spdlog_ex& ex) @@ -168,7 +168,7 @@ int main(int, char*[]) void async_example() { size_t q_size = 4096; //queue size must be power of 2 - spd::set_async_mode(q_size); + spdlog::set_async_mode(q_size); auto async_file = spd::daily_logger_st("async_file_logger", "logs/async_log.txt"); for (int i = 0; i < 100; ++i) async_file->info("Async message #{}", i); @@ -206,7 +206,7 @@ void user_defined_example() // void err_handler_example() { - spd::set_error_handler([](const std::string& msg) { + spdlog::set_error_handler([](const std::string& msg) { std::cerr << "my err handler: " << msg << std::endl; }); // (or logger->set_error_handler(..) to set for specific logger) diff --git a/include/spdlog/details/logger_impl.h b/include/spdlog/details/logger_impl.h index c712b27a..d77e87aa 100644 --- a/include/spdlog/details/logger_impl.h +++ b/include/spdlog/details/logger_impl.h @@ -18,11 +18,11 @@ template inline spdlog::logger::logger(const std::string& logger_name, const It& begin, const It& end): _name(logger_name), _sinks(begin, end), - _formatter(std::make_shared("%+")), - _level(level::info), - _flush_level(level::off), - _last_err_time(0) + _formatter(std::make_shared("%+")) { + _level = level::info; + _flush_level = level::off; + _last_err_time = 0; _err_handler = [this](const std::string &msg) { this->_default_err_handler(msg); @@ -294,3 +294,61 @@ inline const std::vector& spdlog::logger::sinks() const { return _sinks; } + +#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT +#include + +template +inline void spdlog::logger::log(level::level_enum lvl, const wchar_t* msg) +{ + std::wstring_convert > conv; + + log(lvl, conv.to_bytes(msg)); +} + +template +inline void spdlog::logger::log(level::level_enum lvl, const wchar_t* fmt, const Args&... args) +{ + fmt::WMemoryWriter wWriter; + + wWriter.write(fmt, args...); + log(lvl, wWriter.c_str()); +} + +template +inline void spdlog::logger::trace(const wchar_t* fmt, const Args&... args) +{ + log(level::trace, fmt, args...); +} + +template +inline void spdlog::logger::debug(const wchar_t* fmt, const Args&... args) +{ + log(level::debug, fmt, args...); +} + +template +inline void spdlog::logger::info(const wchar_t* fmt, const Args&... args) +{ + log(level::info, fmt, args...); +} + + +template +inline void spdlog::logger::warn(const wchar_t* fmt, const Args&... args) +{ + log(level::warn, fmt, args...); +} + +template +inline void spdlog::logger::error(const wchar_t* fmt, const Args&... args) +{ + log(level::err, fmt, args...); +} + +template +inline void spdlog::logger::critical(const wchar_t* fmt, const Args&... args) +{ + log(level::critical, fmt, args...); +} +#endif // SPDLOG_WCHAR_TO_UTF8_SUPPORT \ No newline at end of file diff --git a/include/spdlog/details/os.h b/include/spdlog/details/os.h index 4d9f60a5..b63ce667 100644 --- a/include/spdlog/details/os.h +++ b/include/spdlog/details/os.h @@ -375,7 +375,7 @@ inline std::string errno_str(int err_num) if(strerror_s(buf, buf_size, err_num) == 0) return std::string(buf); else - return "Unknown error"; + return "Unkown error"; #elif defined(__FreeBSD__) || defined(__APPLE__) || defined(ANDROID) || defined(__SUNPRO_CC) || \ ((_POSIX_C_SOURCE >= 200112L) && ! defined(_GNU_SOURCE)) // posix version @@ -383,7 +383,7 @@ inline std::string errno_str(int err_num) if (strerror_r(err_num, buf, buf_size) == 0) return std::string(buf); else - return "Unknown error"; + return "Unkown error"; #else // gnu version (might not use the given buf, so its retval pointer must be used) return std::string(strerror_r(err_num, buf, buf_size)); diff --git a/include/spdlog/logger.h b/include/spdlog/logger.h index 58b4841a..9a508590 100644 --- a/include/spdlog/logger.h +++ b/include/spdlog/logger.h @@ -51,6 +51,17 @@ public: template void warn(const T&); template void error(const T&); template void critical(const T&); + +#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT + template void log(level::level_enum lvl, const wchar_t* msg); + template void log(level::level_enum lvl, const wchar_t* fmt, const Args&... args); + template void trace(const wchar_t* fmt, const Args&... args); + template void debug(const wchar_t* fmt, const Args&... args); + template void info(const wchar_t* fmt, const Args&... args); + template void warn(const wchar_t* fmt, const Args&... args); + template void error(const wchar_t* fmt, const Args&... args); + template void critical(const wchar_t* fmt, const Args&... args); +#endif // SPDLOG_WCHAR_TO_UTF8_SUPPORT bool should_log(level::level_enum) const; void set_level(level::level_enum); diff --git a/include/spdlog/tweakme.h b/include/spdlog/tweakme.h index 86f66b9e..31e105c3 100644 --- a/include/spdlog/tweakme.h +++ b/include/spdlog/tweakme.h @@ -106,3 +106,10 @@ // // #define SPDLOG_PREVENT_CHILD_FD /////////////////////////////////////////////////////////////////////////////// + + +/////////////////////////////////////////////////////////////////////////////// +// Uncomment to enable wchar_t support (convert to utf8) +// +// #define SPDLOG_WCHAR_TO_UTF8_SUPPORT +///////////////////////////////////////////////////////////////////////////////