more restrictive type conversions

pull/2687/head
Bailey Chittle 3 years ago
parent 6be381bf20
commit 2d0448318e

@ -395,8 +395,35 @@ void replace_default_logger_example()
void attribute_example() {
spdlog::push_context(spdlog::attribute_list{{"attribute_key", "attribute value"}});
spdlog::warn("EXPERIMENTAL: log with attributes");
spdlog::info("EXPERIMENTAL: log with attributes");
spdlog::clear_context();
const int& x1 = 1;
unsigned int x2 = 2;
long x3 = 3;
unsigned long x4 = 4;
long long x5 = 5;
unsigned long long x6 = 6;
spdlog::push_context({{"int_key", x1 }});
spdlog::push_context({{"uint_key", x2 }});
spdlog::push_context({{"uint_ref_key", static_cast<unsigned int&>(x2) }});
spdlog::push_context({{"long", x3 }});
spdlog::push_context({{"ulong", x4 }});
spdlog::push_context({{"llong", x5 }});
spdlog::push_context({{"ullong", x6 }});
// chars shouldnt work?
// spdlog::push_context({{"char", 'a' }});
// floats shouldnt work
// spdlog::push_context({{"float", 1.0f }});
// spdlog::push_context({{"double", 1.0 }});
// bools also shouldnt work
// spdlog::push_context({{"bool", true }});
spdlog::warn("Oops I forgot to clear the context. What will happen?");
// structured logging using attributes
@ -411,7 +438,7 @@ void attribute_example() {
std::string logfmt_pattern = "time=%Y-%m-%dT%H:%M:%S.%f%z name=\"%n\" level=%^%l%$ process=%P thread=%t message=\"%v\"%( %K=\"%V\"%)";
s_logger->set_pattern(std::move(logfmt_pattern));
#endif
s_logger->push_context(spdlog::attribute_list{{"key\n1", "value\n1"}});
s_logger->info("structured logging: test 1");
s_logger->push_context(spdlog::attribute_list{{"key\n2", 1}});

@ -1,7 +1,7 @@
#pragma once
#include <string>
#include <string_view>
// #include <string_view>
#include <vector>
#include "attr_composer.h"
#include <spdlog/common.h>
@ -15,7 +15,12 @@ struct is_string
{};
template<typename T>
struct is_number : public std::integral_constant<bool, std::is_integral<T>::value || std::is_floating_point<T>::value>
struct is_number : public std::integral_constant<bool,
std::is_same<T, int>::value || std::is_same<T, unsigned int>::value
|| std::is_same<T, long>::value || std::is_same<T, unsigned long>::value
|| std::is_same<T, long long>::value || std::is_same<T, unsigned long long>::value
// || std::is_floating_point<T>::value
>
{};
struct attr

Loading…
Cancel
Save