Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fixed Logging.
- Fixed `__CPP_REDIS_LOG` calls with log level as int instead of type. 
- `operator<<` can now be used within `__CPP_REDIS_LOG`
  • Loading branch information
Daniel Keller committed Mar 28, 2020
commit 72b180d61c513f5c84952293b3c2a63c77d0fab9
3 changes: 3 additions & 0 deletions includes/cpp_redis/core/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ namespace cpp_redis {
explicit xmessage(const reply_t &data);

friend std::ostream &operator<<(std::ostream &os, const xmessage &xm);
friend std::string operator<<(const std::string& is, const xmessage &xs);
};

typedef xmessage xmessage_t;
Expand All @@ -99,6 +100,7 @@ namespace cpp_redis {
explicit xstream(const reply_t &data);

friend std::ostream &operator<<(std::ostream &os, const xstream &xs);
friend std::string operator<<(const std::string& is, const xstream &xs);

std::string Stream;
std::vector<xmessage_t> Messages;
Expand All @@ -124,6 +126,7 @@ namespace cpp_redis {
explicit xstream_reply(const reply_t &data);

friend std::ostream &operator<<(std::ostream &os, const xstream_reply &xs);
friend std::string operator<<(const std::string& is, const xstream_reply &xs);

bool is_null() const {
if (empty())
Expand Down
2 changes: 1 addition & 1 deletion includes/cpp_redis/misc/optional.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ struct optional {
template <class U>
enableIf<std::is_convertible<U, T>::value, T>
value_or(U&& v) const {
__CPP_REDIS_LOG(1, "value_or(U&& v)\n")
__CPP_REDIS_LOG(warn, "value_or(U&& v)\n")
return std::forward<U>(v);
}

Expand Down
4 changes: 2 additions & 2 deletions sources/core/consumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ namespace cpp_redis {
// The reply is an array if valid
cpp_redis::xstream_reply s_reply(reply);
if (!s_reply.is_null()) {
__CPP_REDIS_LOG(2, "Stream " << s_reply)
__CPP_REDIS_LOG(info, "Stream " << s_reply)
for (const auto &stream : s_reply) {
for (auto &m : stream.Messages) {
if (m_should_read_pending.load())
Expand Down Expand Up @@ -136,7 +136,7 @@ namespace cpp_redis {
return response;
});
} catch (std::exception &exc) {
__CPP_REDIS_LOG(1,
__CPP_REDIS_LOG(warn,
"Processing failed for message id: " + m.get_id() +
"\nDetails: " + exc.what());
throw exc;
Expand Down
2 changes: 1 addition & 1 deletion sources/core/reply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace cpp_redis {
if (is_integer())
return optional_t<int64_t>(m_int_val);

__CPP_REDIS_LOG(1, "Reply is not an integer");
__CPP_REDIS_LOG(warn, "Reply is not an integer");
return {0};
}

Expand Down
21 changes: 21 additions & 0 deletions sources/core/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ namespace cpp_redis {
return os;
}

std::string operator<<(const std::string& is, const xmessage &xs) {
std::stringstream output;
output << is;
output << xs;
return output.str();
}

xmessage::xmessage() = default;

std::ostream &operator<<(std::ostream &os, const xstream &xs) {
Expand All @@ -84,6 +91,13 @@ namespace cpp_redis {
return os;
}

std::string operator<<(const std::string& is, const xstream &xs) {
std::stringstream output;
output << is;
output << xs;
return output.str();
}

xstream_reply::xstream_reply(const reply &data) {
if (data.is_array()) {
for (auto &d : data.as_array()) {
Expand All @@ -99,6 +113,13 @@ namespace cpp_redis {
return os;
}

std::string operator<<(const std::string& is, const xstream_reply &xs) {
std::stringstream output;
output << is;
output << xs;
return output.str();
}

xinfo_reply::xinfo_reply(const cpp_redis::reply &data) {
if ( data.is_array()) {
auto da = data.as_array();
Expand Down