1
0
mirror of https://github.com/gabime/spdlog.git synced 2025-04-29 20:13:52 +00:00

snprinf for msc ver

This commit is contained in:
gabime 2014-03-02 16:31:13 +02:00
parent b396ff85a7
commit 2ac214aed8
5 changed files with 18 additions and 13 deletions

View File

@ -58,11 +58,11 @@ int main(int argc, char* argv[])
auto &logger2 = c11log::get_logger("logger2"); auto &logger2 = c11log::get_logger("logger2");
//logger2.add_sink(fsink2); //logger2.add_sink(fsink2);
logger2.add_sink(std::make_shared<sinks::null_sink>()); logger2.add_sink(std::make_shared<sinks::null_sink>());
logger2.add_sink(std::make_shared<sinks::stdout_sink>()); logger2.add_sink(std::make_shared<sinks::stdout_sink>());
info_logger info(&logger2); info_logger info(&logger2);
info << "Hello info logger" << "!!"; info << "Hello info logger" << "!!";
return 0; return 0;
auto start = system_clock::now(); auto start = system_clock::now();
const unsigned int howmany = 10000000; const unsigned int howmany = 10000000;
for(unsigned int i = 0; i < howmany ; i++) for(unsigned int i = 0; i < howmany ; i++)

View File

@ -58,7 +58,7 @@ public:
// If the queue is full, block the calling thread until there is room. // If the queue is full, block the calling thread until there is room.
template<typename TT> template<typename TT>
void push(TT&& item) { void push(TT&& item) {
constexpr std::chrono::hours one_hour(1); constexpr std::chrono::hours one_hour(1);
while (!push(std::forward<TT>(item), one_hour)); while (!push(std::forward<TT>(item), one_hour));
} }
@ -86,7 +86,7 @@ public:
// Pop a copy of the front item in the queue into the given item ref. // Pop a copy of the front item in the queue into the given item ref.
// If the queue is empty, block the calling thread util there is item to pop. // If the queue is empty, block the calling thread util there is item to pop.
void pop(T& item) { void pop(T& item) {
constexpr std::chrono::hours one_hour(1); constexpr std::chrono::hours one_hour(1);
while (!pop(item, one_hour)); while (!pop(item, one_hour));
} }

View File

@ -31,3 +31,8 @@ inline std::tm c11log::details::os::localtime()
std::time_t now_t = time(0); std::time_t now_t = time(0);
return localtime(now_t); return localtime(now_t);
} }
// Take care of snprintf in visual studio
#ifdef _MSC_VER
#define snprintf _snprintf
#endif

View File

@ -173,13 +173,13 @@ inline c11log::logger& c11log::get_logger(const std::string& name)
namespace c11log { namespace c11log {
class info_logger { class info_logger {
public: public:
info_logger (c11log::logger* logger):_logger(logger) {} info_logger (c11log::logger* logger):_logger(logger) {}
template<class T> template<class T>
details::line_logger& operator<<(const T& msg) { details::line_logger& operator<<(const T& msg) {
return _logger->info() << msg; return _logger->info() << msg;
} }
private: private:
c11log::logger* _logger; c11log::logger* _logger;
}; };
} }