mirror of
https://github.com/gabime/spdlog.git
synced 2025-11-16 09:28:56 +08:00
Add wchar_t support for Windows.
This commit is contained in:
@@ -2648,6 +2648,11 @@ Any write method will throw ``std::runtime_error`` if the output doesn't fit
|
||||
into the array.
|
||||
|
||||
You can use one of the following typedefs for common character types:
|
||||
#ifdef WIN32
|
||||
#define TMemoryWriter WMemoryWriter
|
||||
#else
|
||||
#define TMemoryWriter MemoryWriter
|
||||
#endif
|
||||
|
||||
+--------------+---------------------------+
|
||||
| Type | Definition |
|
||||
@@ -3152,4 +3157,4 @@ FMT_VARIADIC(int, fprintf, std::FILE *, CStringRef)
|
||||
# include "format.cc"
|
||||
#endif
|
||||
|
||||
#endif // FMT_FORMAT_H_
|
||||
#endif // FMT_FORMAT_H_
|
||||
|
||||
@@ -147,17 +147,33 @@ constexpr inline unsigned short eol_size()
|
||||
#endif
|
||||
|
||||
//fopen_s on non windows for writing
|
||||
inline int fopen_s(FILE** fp, const std::string& filename, const char* mode)
|
||||
inline int fopen_s(FILE** fp, const tstring& filename, tchar* mode)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
*fp = _fsopen((filename.c_str()), mode, _SH_DENYWR);
|
||||
*fp = _wfsopen((filename.c_str()), mode, _SH_DENYWR);
|
||||
return *fp == nullptr;
|
||||
#else
|
||||
*fp = fopen((filename.c_str()), mode);
|
||||
return *fp == nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
inline int remove(const tchar* filename)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return _wremove(filename);
|
||||
#else
|
||||
return std::remove(filename);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline int rename(const tchar* filename1, const tchar* filename2)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return _wrename(filename1, filename2);
|
||||
#else
|
||||
return std::remove(filename1, filename2);
|
||||
#endif
|
||||
}
|
||||
|
||||
//Return utc offset in minutes or -1 on failure
|
||||
|
||||
@@ -48,24 +48,24 @@ inline void spdlog::drop(const std::string &name)
|
||||
}
|
||||
|
||||
// Create multi/single threaded rotating file logger
|
||||
inline std::shared_ptr<spdlog::logger> spdlog::rotating_logger_mt(const std::string& logger_name, const std::string& filename, size_t max_file_size, size_t max_files, bool force_flush)
|
||||
inline std::shared_ptr<spdlog::logger> spdlog::rotating_logger_mt(const std::string& logger_name, const tstring& filename, size_t max_file_size, size_t max_files, bool force_flush)
|
||||
{
|
||||
return create<spdlog::sinks::rotating_file_sink_mt>(logger_name, filename, "txt", max_file_size, max_files, force_flush);
|
||||
return create<spdlog::sinks::rotating_file_sink_mt>(logger_name, filename, L"txt", max_file_size, max_files, force_flush);
|
||||
}
|
||||
|
||||
inline std::shared_ptr<spdlog::logger> spdlog::rotating_logger_st(const std::string& logger_name, const std::string& filename, size_t max_file_size, size_t max_files, bool force_flush)
|
||||
inline std::shared_ptr<spdlog::logger> spdlog::rotating_logger_st(const std::string& logger_name, const tstring& filename, size_t max_file_size, size_t max_files, bool force_flush)
|
||||
{
|
||||
return create<spdlog::sinks::rotating_file_sink_st>(logger_name, filename, "txt", max_file_size, max_files, force_flush);
|
||||
return create<spdlog::sinks::rotating_file_sink_st>(logger_name, filename, L"txt", max_file_size, max_files, force_flush);
|
||||
}
|
||||
|
||||
// Create file logger which creates new file at midnight):
|
||||
inline std::shared_ptr<spdlog::logger> spdlog::daily_logger_mt(const std::string& logger_name, const std::string& filename, int hour, int minute, bool force_flush)
|
||||
inline std::shared_ptr<spdlog::logger> spdlog::daily_logger_mt(const std::string& logger_name, const tstring& filename, int hour, int minute, bool force_flush)
|
||||
{
|
||||
return create<spdlog::sinks::daily_file_sink_mt>(logger_name, filename, "txt", hour, minute, force_flush);
|
||||
return create<spdlog::sinks::daily_file_sink_mt>(logger_name, filename, L"txt", hour, minute, force_flush);
|
||||
}
|
||||
inline std::shared_ptr<spdlog::logger> spdlog::daily_logger_st(const std::string& logger_name, const std::string& filename, int hour, int minute, bool force_flush)
|
||||
inline std::shared_ptr<spdlog::logger> spdlog::daily_logger_st(const std::string& logger_name, const tstring& filename, int hour, int minute, bool force_flush)
|
||||
{
|
||||
return create<spdlog::sinks::daily_file_sink_st>(logger_name, filename, "txt", hour, minute, force_flush);
|
||||
return create<spdlog::sinks::daily_file_sink_st>(logger_name, filename, L"txt", hour, minute, force_flush);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user