Skip to content

Commit

Permalink
Merge pull request #395 from evoskuil/master
Browse files Browse the repository at this point in the history
Add verbose logging, comments, emit log builds.
  • Loading branch information
evoskuil authored May 8, 2024
2 parents 8cc5806 + df193bf commit 965d11c
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 4 deletions.
26 changes: 25 additions & 1 deletion include/bitcoin/network/define.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,43 +50,67 @@
#define WITH_LOGS
#define WITH_LOGP
#define WITH_LOGX
#define WITH_LOGW
////#define WITH_LOGW
#define WITH_LOGR
#define WITH_LOGF
#define WITH_LOGQ
#define WITH_LOGV

////#if defined(WITH_EVENTS)
//// #define HAVE_EVENTS
////#endif
#if defined(WITH_LOGGING)
#define HAVE_LOGGING

/// Objects (shared object construct/destruct).
#if defined(WITH_LOGO)
#define HAVE_LOGO
#endif

/// News (general progression).
#if defined(WITH_LOGN)
#define HAVE_LOGN
#endif

/// Sessions.
#if defined(WITH_LOGS)
#define HAVE_LOGS
#endif

/// Protocols.
#if defined(WITH_LOGP)
#define HAVE_LOGP
#endif

/// ProXy.
#if defined(WITH_LOGX)
#define HAVE_LOGX
#endif

/// Wire communication (currently unused).
#if defined(WITH_LOGW)
#define HAVE_LOGW
#endif

/// Remote (peer errors).
#if defined(WITH_LOGR)
#define HAVE_LOGR
#endif

/// Fault (own errors).
#if defined(WITH_LOGF)
#define HAVE_LOGF
#endif

/// Quitting connections (e.g. read/write/send abort).
#if defined(WITH_LOGQ)
#define HAVE_LOGQ
#endif

/// Verbose (ad-hoc debugging).
#if defined(WITH_LOGV)
#define HAVE_LOGV
#endif
#endif

#include <bitcoin/network/error.hpp>
Expand Down
17 changes: 14 additions & 3 deletions include/bitcoin/network/log/levels.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,30 @@ enum : uint8_t
{
application, // Unused by network lib
news, // News
objects, // Objects
session, // Sessions/connect/accept
protocol, // Protocols
proxy, // proXy/socket/channel
wire, // Wire sharking
remote, // Remote behavior
fault, // Fault
quit // Quitting
quit, // Quitting
objects, // Objects
verbose // Verbose
};

// LOG_ONLY() is insufficient for individual disablement.
#if defined(HAVE_LOGGING)
#define LOG_ONLY(name) name
#define LOG(level_, message) \
BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT) \
log.write(network::levels::level_) << message << std::endl; \
BC_POP_WARNING()
#define LOG_LOG(name, level_) \
log.write(network::levels::application) << name \
<< network::levels::level_ << std::endl;
#else
#define LOG_ONLY(name)
#define LOG(level, message)
#define LOG_LOG(level_, message)
#endif

#if defined(HAVE_LOGO)
Expand Down Expand Up @@ -128,6 +132,13 @@ enum : uint8_t
#define LOGQ(message)
#endif

#if defined(HAVE_LOGV)
constexpr auto verbose_defined = true;
#define LOGV(message) LOG(verbose, message)
#else
#define LOGV(message)
constexpr auto verbose_defined = false;
#endif

} // namespace levels
} // namespace network
Expand Down
11 changes: 11 additions & 0 deletions src/p2p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ p2p::p2p(const settings& settings, const logger& log) NOEXCEPT
reporter(log)
{
BC_ASSERT_MSG(!is_zero(settings.threads), "empty threadpool");

LOG_LOG("News logging compiled....: ", news_defined);
LOG_LOG("Session logging compiled.: ", session_defined);
LOG_LOG("Protocol logging compiled: ", protocol_defined);
LOG_LOG("ProXy logging compiled...: ", proxy_defined);
LOG_LOG("Wire logging compiled....: ", wire_defined);
LOG_LOG("Remote logging compiled..: ", remote_defined);
LOG_LOG("Fault logging compiled...: ", fault_defined);
LOG_LOG("Quit logging compiled....: ", quit_defined);
LOG_LOG("Object logging compiled..: ", objects_defined);
LOG_LOG("Verbose logging compiled.: ", verbose_defined);
}

p2p::~p2p() NOEXCEPT
Expand Down

0 comments on commit 965d11c

Please sign in to comment.