1
0
mirror of https://github.com/gabime/spdlog.git synced 2025-04-01 02:42:41 +08:00
This commit is contained in:
gabime 2019-12-08 17:08:20 +02:00
parent abbbda6f74
commit 0f24399887
7 changed files with 144 additions and 161 deletions

View File

@ -4,21 +4,21 @@
// spdlog usage example
#include <spdlog/spdlog.h>
#include <spdlog/cfg/env.h>
int main(int, char *[]) {
try {
int main(int, char *[])
{
try
{
auto cfg = spdlog::cfg::from_env();
for (auto &item : cfg)
{
spdlog::info("['{}'] level: {} pattern: {}", item.first, spdlog::level::to_string_view(item.second.level), item.second.pattern);
}
}catch(spdlog::spdlog_ex& ex){
}
catch (spdlog::spdlog_ex &ex)
{
spdlog::info("spdlog_ex: {}", ex.what());
}
}

View File

@ -22,9 +22,8 @@ namespace spdlog {
// inplace convert to lowercase
inline std::string &to_lower_(std::string &str)
{
std::transform(str.begin(), str.end(), str.begin(), [](char ch) {
return static_cast<char>((ch >= 'A' && ch <= 'Z') ? ch + ('a' - 'A') : ch);
});
std::transform(
str.begin(), str.end(), str.begin(), [](char ch) { return static_cast<char>((ch >= 'A' && ch <= 'Z') ? ch + ('a' - 'A') : ch); });
return str;
}
@ -48,7 +47,9 @@ namespace spdlog {
if (n == std::string::npos)
{
v = str;
} else{
}
else
{
k = str.substr(0, n);
v = str.substr(n + 1);
}
@ -69,7 +70,6 @@ namespace spdlog {
return rv;
}
inline void load_levels_(cfg_map &configs)
{
using details::os::getenv;

View File

@ -8,13 +8,14 @@
#include <unordered_map>
// config spdlog from environment variables
namespace spdlog
namespace spdlog {
namespace cfg {
struct logger_cfg
{
namespace cfg
{
struct logger_cfg {
logger_cfg(level::level_enum level, std::string pattern):
level{level}, pattern(std::move(pattern)) {}
logger_cfg(level::level_enum level, std::string pattern)
: level{level}
, pattern(std::move(pattern))
{}
level::level_enum level;
std::string pattern;
@ -30,8 +31,8 @@ namespace spdlog
//
// Note: will set the level to info if finds unknown level in SPDLOG_LEVEL
cfg_map from_env();
}
}
} // namespace cfg
} // namespace spdlog
#ifdef SPDLOG_HEADER_ONLY
#include "env-inl.h"

View File

@ -547,7 +547,6 @@ std::string SPDLOG_INLINE getenv(const char* field)
char *buf = ::getenv(field);
return buf ? buf : std::string{};
#endif
}
} // namespace os

View File

@ -16,7 +16,6 @@
#pragma GCC diagnostic ignored "-Wsign-conversion"
#endif // __GNUC__ || __clang__
#if !defined(SPDLOG_FMT_EXTERNAL)
#ifdef SPDLOG_HEADER_ONLY
#ifndef FMT_HEADER_ONLY

View File

@ -15,20 +15,16 @@
#if !defined(SPDLOG_FMT_EXTERNAL)
#include "spdlog/fmt/bundled/format-inl.h"
// pop warnings supressions
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic pop
#endif
FMT_BEGIN_NAMESPACE
template struct FMT_API internal::basic_data<void>;
// Workaround a bug in MSVC2013 that prevents instantiation of format_float.
int (*instantiate_format_float)(double, int, internal::float_specs,
internal::buffer<char>&) =
internal::format_float;
int (*instantiate_format_float)(double, int, internal::float_specs, internal::buffer<char> &) = internal::format_float;
#ifndef FMT_STATIC_THOUSANDS_SEPARATOR
template FMT_API internal::locale_ref::locale_ref(const std::locale &loc);
@ -43,26 +39,16 @@ template FMT_API char internal::decimal_point_impl(locale_ref);
template FMT_API void internal::buffer<char>::append(const char *, const char *);
template FMT_API void internal::arg_map<format_context>::init(
const basic_format_args<format_context>& args);
template FMT_API void internal::arg_map<format_context>::init(const basic_format_args<format_context> &args);
template FMT_API std::string internal::vformat<char>(
string_view, basic_format_args<format_context>);
template FMT_API std::string internal::vformat<char>(string_view, basic_format_args<format_context>);
template FMT_API format_context::iterator internal::vformat_to(
internal::buffer<char>&, string_view, basic_format_args<format_context>);
template FMT_API format_context::iterator internal::vformat_to(internal::buffer<char> &, string_view, basic_format_args<format_context>);
template FMT_API int internal::snprintf_float(double, int,
internal::float_specs,
internal::buffer<char>&);
template FMT_API int internal::snprintf_float(long double, int,
internal::float_specs,
internal::buffer<char>&);
template FMT_API int internal::format_float(double, int, internal::float_specs,
internal::buffer<char>&);
template FMT_API int internal::format_float(long double, int,
internal::float_specs,
internal::buffer<char>&);
template FMT_API int internal::snprintf_float(double, int, internal::float_specs, internal::buffer<char> &);
template FMT_API int internal::snprintf_float(long double, int, internal::float_specs, internal::buffer<char> &);
template FMT_API int internal::format_float(double, int, internal::float_specs, internal::buffer<char> &);
template FMT_API int internal::format_float(long double, int, internal::float_specs, internal::buffer<char> &);
// Explicit instantiations for wchar_t.
@ -70,11 +56,9 @@ template FMT_API std::string internal::grouping_impl<wchar_t>(locale_ref);
template FMT_API wchar_t internal::thousands_sep_impl(locale_ref);
template FMT_API wchar_t internal::decimal_point_impl(locale_ref);
template FMT_API void internal::buffer<wchar_t>::append(const wchar_t*,
const wchar_t*);
template FMT_API void internal::buffer<wchar_t>::append(const wchar_t *, const wchar_t *);
template FMT_API std::wstring internal::vformat<wchar_t>(
wstring_view, basic_format_args<wformat_context>);
template FMT_API std::wstring internal::vformat<wchar_t>(wstring_view, basic_format_args<wformat_context>);
FMT_END_NAMESPACE
#endif