better support for custom eol
This commit is contained in:
parent
6760dcebc8
commit
10d5292bbb
@ -20,11 +20,13 @@
|
|||||||
#include <spdlog/details/null_mutex.h>
|
#include <spdlog/details/null_mutex.h>
|
||||||
|
|
||||||
|
|
||||||
//visual studio upto 2013 does not support noexcept
|
//visual studio upto 2013 does not support noexcept nor constexpr
|
||||||
#if defined(_MSC_VER) && (_MSC_VER < 1900)
|
#if defined(_MSC_VER) && (_MSC_VER < 1900)
|
||||||
#define SPDLOG_NOEXCEPT throw()
|
#define SPDLOG_NOEXCEPT throw()
|
||||||
|
#define SPDLOG_CONSTEXPR
|
||||||
#else
|
#else
|
||||||
#define SPDLOG_NOEXCEPT noexcept
|
#define SPDLOG_NOEXCEPT noexcept
|
||||||
|
#define SPDLOG_CONSTEXPR constexpr
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -112,29 +112,18 @@ inline bool operator!=(const std::tm& tm1, const std::tm& tm2)
|
|||||||
return !(tm1 == tm2);
|
return !(tm1 == tm2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// eol at end of each log line
|
||||||
|
#if !defined (SPDLOG_EOL)
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
inline const char* eol()
|
#define SPDLOG_EOL "\r\n"
|
||||||
{
|
|
||||||
return "\r\n";
|
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
constexpr inline const char* eol()
|
#define SPDLOG_EOL "\n"
|
||||||
{
|
#endif
|
||||||
return "\n";
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef _WIN32
|
SPDLOG_CONSTEXPR static const char* eol = SPDLOG_EOL;
|
||||||
inline unsigned short eol_size()
|
SPDLOG_CONSTEXPR static int eol_size = sizeof(SPDLOG_EOL) - 1;
|
||||||
{
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
constexpr inline unsigned short eol_size()
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//fopen_s on non windows for writing
|
//fopen_s on non windows for writing
|
||||||
inline int fopen_s(FILE** fp, const filename_t& filename, const filename_t& mode)
|
inline int fopen_s(FILE** fp, const filename_t& filename, const filename_t& mode)
|
||||||
|
@ -619,11 +619,7 @@ inline void spdlog::pattern_formatter::format(details::log_msg& msg)
|
|||||||
f->format(msg, tm_time);
|
f->format(msg, tm_time);
|
||||||
}
|
}
|
||||||
//write eol
|
//write eol
|
||||||
#if defined(SPDLOG_EOL)
|
msg.formatted.write(details::os::eol, details::os::eol_size);
|
||||||
msg.formatted << SPDLOG_EOL;
|
|
||||||
#else
|
|
||||||
msg.formatted.write(details::os::eol(), details::os::eol_size());
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
catch(const fmt::FormatError& e)
|
catch(const fmt::FormatError& e)
|
||||||
{
|
{
|
||||||
|
@ -65,6 +65,6 @@
|
|||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// uncomment the below to override spdlog's default eol
|
// Uncomment to override default eol ("\n" or "\r\n" under Linux/Windows)
|
||||||
// #define SPDLOG_EOL "\n"
|
// #define SPDLOG_EOL ";-)\n"
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -12,10 +12,8 @@ std::string log_info(const T& what, spdlog::level::level_enum logger_level = spd
|
|||||||
oss_logger.set_level(logger_level);
|
oss_logger.set_level(logger_level);
|
||||||
oss_logger.set_pattern("%v");
|
oss_logger.set_pattern("%v");
|
||||||
oss_logger.info() << what;
|
oss_logger.info() << what;
|
||||||
|
|
||||||
//strip last eol and return the logged string
|
return oss.str().substr(0, oss.str().length() - spdlog::details::os::eol_size);
|
||||||
auto eol_size = strlen(spdlog::details::os::eol());
|
|
||||||
return oss.str().substr(0, oss.str().length() - eol_size);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user