@@ -49,35 +49,35 @@ extern bool server_log_json;
49
49
#define LOG_WARNING (MSG, ...) server_log(" WARN" , __func__, __LINE__, MSG, __VA_ARGS__)
50
50
#define LOG_INFO ( MSG, ...) server_log(" INFO" , __func__, __LINE__, MSG, __VA_ARGS__)
51
51
52
- static inline void server_log (const char *level, const char *function, int line, const char *message, const nlohmann::ordered_json & extra);
52
+ static inline void server_log (const char * level, const char * function, int line, const char * message, const json & extra);
53
53
54
54
template <typename T>
55
- static T json_value (const json &body, const std::string &key, const T &default_value) {
55
+ static T json_value (const json & body, const std::string & key, const T & default_value) {
56
56
// Fallback null to default value
57
- if (body.contains (key) && !body.at (key).is_null ()){
57
+ if (body.contains (key) && !body.at (key).is_null ()) {
58
58
try {
59
- return body.value (key, default_value );
60
- }
61
- catch (nlohmann::json_abi_v3_11_3::detail::type_error const &){
62
- std::string message = " Wrong type supplied for parameter '" + key + " '. Expected '" + typeid (default_value).name () + " ', using default value." ;
63
- server_log ( " WARN " , __func__, __LINE__, message .c_str (), body);
59
+ return body.at (key);
60
+ } catch (NLOHMANN_JSON_NAMESPACE::detail::type_error const &) {
61
+ std::stringstream ss;
62
+ ss << " Wrong type supplied for parameter '" << key << " '. Expected '" << json (default_value).type_name () << " ', using default value." ;
63
+ LOG_WARNING (ss. str () .c_str (), body);
64
64
return default_value;
65
65
}
66
66
} else {
67
67
return default_value;
68
68
}
69
69
}
70
70
71
- static inline void server_log (const char *level, const char *function, int line, const char *message, const nlohmann::ordered_json & extra) {
71
+ static inline void server_log (const char * level, const char * function, int line, const char * message, const json & extra) {
72
72
std::stringstream ss_tid;
73
73
ss_tid << std::this_thread::get_id ();
74
- json log = nlohmann::ordered_json {
74
+ json log = json {
75
75
{" tid" , ss_tid.str ()},
76
76
{" timestamp" , time (nullptr )},
77
77
};
78
78
79
79
if (server_log_json) {
80
- log.merge_patch ( {
80
+ log.merge_patch ({
81
81
{" level" , level},
82
82
{" function" , function},
83
83
{" line" , line},
@@ -98,7 +98,7 @@ static inline void server_log(const char *level, const char *function, int line,
98
98
}
99
99
std::stringstream ss;
100
100
ss << buf << " |" ;
101
- for (const auto & el : log.items ())
101
+ for (const auto & el : log.items ())
102
102
{
103
103
const std::string value = el.value ().dump (-1 , ' ' , false , json::error_handler_t ::replace);
104
104
ss << " " << el.key () << " =" << value;
0 commit comments