aboutsummaryrefslogtreecommitdiff
path: root/src/logging.h
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2019-09-26 13:31:57 -0400
committerMarcoFalke <falke.marco@gmail.com>2019-11-04 10:42:29 -0500
commitfa1936f57bbf5aebb1f8fc18701441d79219d443 (patch)
tree82b944a2f5ad061909217366ed6bfe403eab654c /src/logging.h
parentfba574c908bb61eff1a0e83c935f3526ba9035f2 (diff)
downloadbitcoin-fa1936f57bbf5aebb1f8fc18701441d79219d443.tar.xz
logging: Add member for arbitrary print callbacks
Diffstat (limited to 'src/logging.h')
-rw-r--r--src/logging.h20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/logging.h b/src/logging.h
index e37c0c823b..9ed41c2b98 100644
--- a/src/logging.h
+++ b/src/logging.h
@@ -77,6 +77,9 @@ namespace BCLog {
std::string LogTimestampStr(const std::string& str);
+ /** Slots that connect to the print signal */
+ std::list<std::function<void(const std::string&)>> m_print_callbacks /* GUARDED_BY(m_cs) */ {};
+
public:
bool m_print_to_console = false;
bool m_print_to_file = false;
@@ -95,7 +98,22 @@ namespace BCLog {
bool Enabled() const
{
std::lock_guard<std::mutex> scoped_lock(m_cs);
- return m_buffering || m_print_to_console || m_print_to_file;
+ return m_buffering || m_print_to_console || m_print_to_file || !m_print_callbacks.empty();
+ }
+
+ /** Connect a slot to the print signal and return the connection */
+ std::list<std::function<void(const std::string&)>>::iterator PushBackCallback(std::function<void(const std::string&)> fun)
+ {
+ std::lock_guard<std::mutex> scoped_lock(m_cs);
+ m_print_callbacks.push_back(std::move(fun));
+ return --m_print_callbacks.end();
+ }
+
+ /** Delete a connection */
+ void DeleteCallback(std::list<std::function<void(const std::string&)>>::iterator it)
+ {
+ std::lock_guard<std::mutex> scoped_lock(m_cs);
+ m_print_callbacks.erase(it);
}
/** Start logging (and flush all buffered messages) */