diff --git a/README.md b/README.md index b8aaca05..be0e60a0 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,19 @@ Very fast, header only, C++ logging library. [![Build Status](https://travis-ci. ## Install -Just copy the source [folder](https://github.com/gabime/spdlog/tree/master/include/spdlog) to your build tree and use a C++11 compiler +#### Just copy the headers: + +* Copy the source [folder](https://github.com/gabime/spdlog/tree/master/include/spdlog) to your build tree and use a C++11 compiler. + +#### Or use your favourite package manager: + +* Ubuntu: `apt-get install libspdlog-dev` +* Homebrew: `brew install spdlog` +* FreeBSD: `cd /usr/ports/devel/spdlog/ && make install clean` +* Fedora: `yum install spdlog` +* Arch Linux: `pacman -S spdlog-git` +* vcpkg: `vcpkg install spdlog` + ## Platforms * Linux, FreeBSD, Solaris diff --git a/include/spdlog/details/pattern_formatter_impl.h b/include/spdlog/details/pattern_formatter_impl.h index 3f4e9a2c..2fefaa3c 100644 --- a/include/spdlog/details/pattern_formatter_impl.h +++ b/include/spdlog/details/pattern_formatter_impl.h @@ -18,6 +18,7 @@ #include #include #include +#include namespace spdlog { @@ -78,42 +79,60 @@ static int to12h(const tm& t) } //Abbreviated weekday name -static const std::string days[] { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; +using days_array = std::array; +static const days_array& days() +{ + static const days_array arr{ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; + return arr; +} class a_formatter:public flag_formatter { void format(details::log_msg& msg, const std::tm& tm_time) override { - msg.formatted << days[tm_time.tm_wday]; + msg.formatted << days()[tm_time.tm_wday]; } }; //Full weekday name -static const std::string full_days[] { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }; +static const days_array& full_days() +{ + static const days_array arr{ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }; + return arr; +} class A_formatter:public flag_formatter { void format(details::log_msg& msg, const std::tm& tm_time) override { - msg.formatted << full_days[tm_time.tm_wday]; + msg.formatted << full_days()[tm_time.tm_wday]; } }; //Abbreviated month -static const std::string months[] { "Jan", "Feb", "Mar", "Apr", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec" }; +using months_array = std::array; +static const months_array& months() +{ + static const months_array arr{ "Jan", "Feb", "Mar", "Apr", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec" }; + return arr; +} class b_formatter:public flag_formatter { void format(details::log_msg& msg, const std::tm& tm_time) override { - msg.formatted << months[tm_time.tm_mon]; + msg.formatted << months()[tm_time.tm_mon]; } }; //Full month name -static const std::string full_months[] { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; +static const months_array& full_months() +{ + static const months_array arr{ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; + return arr; +} class B_formatter:public flag_formatter { void format(details::log_msg& msg, const std::tm& tm_time) override { - msg.formatted << full_months[tm_time.tm_mon]; + msg.formatted << full_months()[tm_time.tm_mon]; } }; @@ -138,7 +157,7 @@ class c_formatter:public flag_formatter { void format(details::log_msg& msg, const std::tm& tm_time) override { - msg.formatted << days[tm_time.tm_wday] << ' ' << months[tm_time.tm_mon] << ' ' << tm_time.tm_mday << ' '; + msg.formatted << days()[tm_time.tm_wday] << ' ' << months()[tm_time.tm_mon] << ' ' << tm_time.tm_mday << ' '; pad_n_join(msg.formatted, tm_time.tm_hour, tm_time.tm_min, tm_time.tm_sec, ':') << ' ' << tm_time.tm_year + 1900; } }; diff --git a/include/spdlog/spdlog.h b/include/spdlog/spdlog.h index b4bfc84e..6b93a7a1 100644 --- a/include/spdlog/spdlog.h +++ b/include/spdlog/spdlog.h @@ -2,12 +2,13 @@ // Copyright(c) 2015 Gabi Melman. // Distributed under the MIT License (http://opensource.org/licenses/MIT) // - // spdlog main header file. // see example.cpp for usage example #pragma once +#define SPDLOG_VERSION "0.12.0" + #include #include #include