Skip to content

Commit

Permalink
add trace log-level
Browse files Browse the repository at this point in the history
  • Loading branch information
ksedgwic committed Apr 25, 2024
1 parent 6f7d9c6 commit b960ec0
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Boltz/Detail/ClaimTxHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ std::string ClaimTxHandler::logprefix(std::string msg) {
+ msg
;
}
Ev::Io<void> ClaimTxHandler::logt(std::string msg) {
return env.logt(logprefix(msg));
}
Ev::Io<void> ClaimTxHandler::logd(std::string msg) {
return env.logd(logprefix(msg));
}
Expand Down
1 change: 1 addition & 0 deletions Boltz/Detail/ClaimTxHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class ClaimTxHandler : public std::enable_shared_from_this<ClaimTxHandler> {
Ev::Io<void> core_run();

/* Wrappers. */
Ev::Io<void> logt(std::string);
Ev::Io<void> logd(std::string);
Ev::Io<void> loge(std::string);
std::string logprefix(std::string);
Expand Down
3 changes: 3 additions & 0 deletions Boltz/Detail/ServiceImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ namespace Boltz { namespace Detail {
std::string ServiceImpl::prefixlog(std::string msg) {
return std::string("Boltz::Service(\"") + label + "\"): " + msg;
}
Ev::Io<void> ServiceImpl::logt(std::string msg) {
return env.logt(prefixlog(std::move(msg)));
}
Ev::Io<void> ServiceImpl::logd(std::string msg) {
return env.logd(prefixlog(std::move(msg)));
}
Expand Down
1 change: 1 addition & 0 deletions Boltz/Detail/ServiceImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class ServiceImpl : public Service {

private:
/* Logging. */
Ev::Io<void> logt(std::string);
Ev::Io<void> logd(std::string);
Ev::Io<void> loge(std::string);
std::string prefixlog(std::string);
Expand Down
3 changes: 3 additions & 0 deletions Boltz/Detail/SwapSetupHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ auto const max_timeout = std::uint32_t(288);

namespace Boltz { namespace Detail {

Ev::Io<void> SwapSetupHandler::logt(std::string msg) {
return env.logt(prefixlog(std::move(msg)));
}
Ev::Io<void> SwapSetupHandler::logd(std::string msg) {
return env.logd(prefixlog(std::move(msg)));
}
Expand Down
1 change: 1 addition & 0 deletions Boltz/Detail/SwapSetupHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class SwapSetupHandler
private:
Ev::Io<void> core_run();

Ev::Io<void> logt(std::string);
Ev::Io<void> logd(std::string);
Ev::Io<void> loge(std::string);
std::string prefixlog(std::string);
Expand Down
7 changes: 7 additions & 0 deletions Boltz/EnvIF.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ class EnvIF {
virtual
Ev::Io<bool> broadcast_tx(Bitcoin::Tx) =0;

/** Boltz::EnvIF::logt
*
* @brief prints a Trace-level log.
*/
virtual
Ev::Io<void> logt(std::string) =0;

/** Boltz::EnvIF::logd
*
* @brief prints a Debug-level log.
Expand Down
5 changes: 5 additions & 0 deletions Boss/Mod/BoltzSwapper/Env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ Ev::Io<bool> Env::broadcast_tx(Bitcoin::Tx n_tx) {
});
}

Ev::Io<void> Env::logt(std::string msg) {
return Boss::log( bus, Trace
, "%s", msg.c_str()
);
}
Ev::Io<void> Env::logd(std::string msg) {
return Boss::log( bus, Debug
, "%s", msg.c_str()
Expand Down
1 change: 1 addition & 0 deletions Boss/Mod/BoltzSwapper/Env.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class Env : public Boltz::EnvIF {
/* Boltz::EnvIF. */
Ev::Io<std::uint32_t> get_feerate() override;
Ev::Io<bool> broadcast_tx(Bitcoin::Tx) override;
Ev::Io<void> logt(std::string) override;
Ev::Io<void> logd(std::string) override;
Ev::Io<void> loge(std::string) override;
};
Expand Down
1 change: 1 addition & 0 deletions Boss/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Ev::Io<void> log(S::Bus& bus, LogLevel l, const char *fmt, ...) {

auto level_string = std::string();
switch (l) {
case Trace: level_string = std::string("trace"); break;
case Debug: level_string = std::string("debug"); break;
case Info: level_string = std::string("info"); break;
case Warn: level_string = std::string("warn"); break;
Expand Down
1 change: 1 addition & 0 deletions Boss/log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace S { class Bus; }
namespace Boss {

enum LogLevel {
Trace,
Debug,
Info,
Warn,
Expand Down
6 changes: 6 additions & 0 deletions dev-boltz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ class Env : public Boltz::EnvIF {
explicit
Env(Ev::ThreadPool& threadpool) : conn(threadpool) { }

Ev::Io<void> logt(std::string msg) override {
return Ev::lift().then([msg]() {
std::cout << "TRACE " << msg << std::endl;
return Ev::lift();
});
}
Ev::Io<void> logd(std::string msg) override {
return Ev::lift().then([msg]() {
std::cout << "DEBUG " << msg << std::endl;
Expand Down

0 comments on commit b960ec0

Please sign in to comment.