Commit a0f6b4af authored by Dominik Charousset's avatar Dominik Charousset

Improve logging

parent 7076ae18
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <type_traits> #include <type_traits>
#include "caf/config.hpp" #include "caf/config.hpp"
#include "caf/to_string.hpp"
#include "caf/abstract_actor.hpp" #include "caf/abstract_actor.hpp"
#include "caf/detail/demangle.hpp" #include "caf/detail/demangle.hpp"
......
...@@ -95,13 +95,20 @@ class event_based_resume { ...@@ -95,13 +95,20 @@ class event_based_resume {
&& d->planned_exit_reason() == exit_reason::not_exited)); && d->planned_exit_reason() == exit_reason::not_exited));
try { try {
if (!d->is_initialized()) { if (!d->is_initialized()) {
CAF_LOG_DEBUG("initialize actor");
d->is_initialized(true); d->is_initialized(true);
auto bhvr = d->make_behavior(); auto bhvr = d->make_behavior();
CAF_LOG_DEBUG_IF(!bhvr, "make_behavior() did not return a behavior, "
<< "bhvr_stack().empty() = "
<< std::boolalpha << d->bhvr_stack().empty());
if (bhvr) { if (bhvr) {
// make_behavior() did return a behavior instead of using become() // make_behavior() did return a behavior instead of using become()
CAF_LOG_DEBUG("make_behavior() did return a valid behavior");
d->become(std::move(bhvr)); d->become(std::move(bhvr));
} }
if (actor_done()) { if (actor_done()) {
CAF_LOG_DEBUG("actor_done() returned true right "
<< "after make_behavior()");
return resume_result::done; return resume_result::done;
} }
} }
......
...@@ -52,15 +52,13 @@ inline std::string to_string_impl(const T& what) { ...@@ -52,15 +52,13 @@ inline std::string to_string_impl(const T& what) {
} // namespace detail } // namespace detail
inline std::string to_string(const message& what) { std::string to_string(const actor_addr& what);
return detail::to_string_impl(what);
}
inline std::string to_string(const actor& what) { inline std::string to_string(const actor& what) {
return detail::to_string_impl(what); return to_string(what.address());
} }
inline std::string to_string(const actor_addr& what) { inline std::string to_string(const message& what) {
return detail::to_string_impl(what); return detail::to_string_impl(what);
} }
......
...@@ -102,11 +102,13 @@ size_t abstract_actor::detach_impl(const attachable::token& what, ...@@ -102,11 +102,13 @@ size_t abstract_actor::detach_impl(const attachable::token& what,
} }
void abstract_actor::detach(const attachable::token& what) { void abstract_actor::detach(const attachable::token& what) {
CAF_LOG_TRACE("");
guard_type guard{m_mtx}; guard_type guard{m_mtx};
detach_impl(what, m_attachables_head); detach_impl(what, m_attachables_head);
} }
bool abstract_actor::link_impl(linking_operation op, const actor_addr& other) { bool abstract_actor::link_impl(linking_operation op, const actor_addr& other) {
CAF_LOG_TRACE(CAF_ARG(op) << ", " << CAF_TSARG(other));
switch (op) { switch (op) {
case establish_link_op: case establish_link_op:
return establish_link_impl(other); return establish_link_impl(other);
...@@ -121,6 +123,7 @@ bool abstract_actor::link_impl(linking_operation op, const actor_addr& other) { ...@@ -121,6 +123,7 @@ bool abstract_actor::link_impl(linking_operation op, const actor_addr& other) {
} }
bool abstract_actor::establish_link_impl(const actor_addr& other) { bool abstract_actor::establish_link_impl(const actor_addr& other) {
CAF_LOG_TRACE(CAF_TSARG(other));
if (other && other != this) { if (other && other != this) {
guard_type guard{m_mtx}; guard_type guard{m_mtx};
auto ptr = actor_cast<abstract_actor_ptr>(other); auto ptr = actor_cast<abstract_actor_ptr>(other);
...@@ -140,6 +143,7 @@ bool abstract_actor::establish_link_impl(const actor_addr& other) { ...@@ -140,6 +143,7 @@ bool abstract_actor::establish_link_impl(const actor_addr& other) {
} }
bool abstract_actor::establish_backlink_impl(const actor_addr& other) { bool abstract_actor::establish_backlink_impl(const actor_addr& other) {
CAF_LOG_TRACE(CAF_TSARG(other));
uint32_t reason = exit_reason::not_exited; uint32_t reason = exit_reason::not_exited;
default_attachable::observe_token tk{other, default_attachable::link}; default_attachable::observe_token tk{other, default_attachable::link};
if (other && other != this) { if (other && other != this) {
...@@ -163,6 +167,7 @@ bool abstract_actor::establish_backlink_impl(const actor_addr& other) { ...@@ -163,6 +167,7 @@ bool abstract_actor::establish_backlink_impl(const actor_addr& other) {
} }
bool abstract_actor::remove_link_impl(const actor_addr& other) { bool abstract_actor::remove_link_impl(const actor_addr& other) {
CAF_LOG_TRACE(CAF_TSARG(other));
if (!other) { if (!other) {
return false; return false;
} }
...@@ -178,6 +183,7 @@ bool abstract_actor::remove_link_impl(const actor_addr& other) { ...@@ -178,6 +183,7 @@ bool abstract_actor::remove_link_impl(const actor_addr& other) {
} }
bool abstract_actor::remove_backlink_impl(const actor_addr& other) { bool abstract_actor::remove_backlink_impl(const actor_addr& other) {
CAF_LOG_TRACE(CAF_TSARG(other));
default_attachable::observe_token tk{other, default_attachable::link}; default_attachable::observe_token tk{other, default_attachable::link};
if (other && other != this) { if (other && other != this) {
guard_type guard{m_mtx}; guard_type guard{m_mtx};
...@@ -191,8 +197,7 @@ actor_addr abstract_actor::address() const { ...@@ -191,8 +197,7 @@ actor_addr abstract_actor::address() const {
} }
void abstract_actor::cleanup(uint32_t reason) { void abstract_actor::cleanup(uint32_t reason) {
// log as 'actor' CAF_LOG_TRACE(CAF_ARG(reason));
CAF_LOGM_TRACE("caf::actor", CAF_ARG(m_id) << ", " << CAF_ARG(reason));
CAF_REQUIRE(reason != exit_reason::not_exited); CAF_REQUIRE(reason != exit_reason::not_exited);
// move everyhting out of the critical section before processing it // move everyhting out of the critical section before processing it
attachable_ptr head; attachable_ptr head;
......
...@@ -164,7 +164,7 @@ int node_id::compare(const node_id& other) const { ...@@ -164,7 +164,7 @@ int node_id::compare(const node_id& other) const {
std::string to_string(const node_id& what) { std::string to_string(const node_id& what) {
std::ostringstream oss; std::ostringstream oss;
oss << what.process_id() << "@" << to_string(what.host_id()); oss << to_string(what.host_id()) << ":" << what.process_id();
return oss.str(); return oss.str();
} }
......
...@@ -512,6 +512,15 @@ string to_string_impl(const void* what, const uniform_type_info* utype) { ...@@ -512,6 +512,15 @@ string to_string_impl(const void* what, const uniform_type_info* utype) {
} // namespace detail } // namespace detail
std::string to_string(const actor_addr& what) {
if (what == invalid_actor_addr) {
return "0@00000000000000000000:0";
}
std::ostringstream oss;
oss << what.id() << "@" << to_string(what.node());
return oss.str();
}
string to_verbose_string(const std::exception& e) { string to_verbose_string(const std::exception& e) {
std::ostringstream oss; std::ostringstream oss;
oss << detail::demangle(typeid(e)) << ": " << e.what(); oss << detail::demangle(typeid(e)) << ": " << e.what();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment