Browse Source

Merge pull request #110 from ethereum-mining/logs

Simplify log output
master
Paweł Bylica 7 years ago
committed by GitHub
parent
commit
e8b0cd2a99
  1. 12
      libdevcore/Guards.h
  2. 22
      libdevcore/Log.cpp
  3. 7
      libdevcore/Log.h

12
libdevcore/Guards.h

@ -39,18 +39,6 @@ struct GenericGuardBool: GuardType
bool b = true;
};
/** @brief Simple lock that waits for release without making context switch */
class SpinLock
{
public:
SpinLock() { m_lock.clear(); }
void lock() { while (m_lock.test_and_set(std::memory_order_acquire)) {} }
void unlock() { m_lock.clear(std::memory_order_release); }
private:
std::atomic_flag m_lock;
};
using SpinGuard = std::lock_guard<SpinLock>;
template <class N>
class Notified
{

22
libdevcore/Log.cpp

@ -130,11 +130,6 @@ string dev::ThreadContext::join(string const& _prior)
return g_logThreadContext.join(_prior);
}
// foward declare without all of Windows.h
#ifdef _WIN32
extern "C" __declspec(dllimport) void __stdcall OutputDebugStringA(const char* lpOutputString);
#endif
string dev::getThreadName()
{
#if defined(__linux__) || defined(__APPLE__)
@ -158,20 +153,7 @@ void dev::setThreadName(char const* _n)
#endif
}
void dev::simpleDebugOut(std::string const& _s, char const*)
void dev::simpleDebugOut(std::string const& _s)
{
static SpinLock s_lock;
SpinGuard l(s_lock);
cerr << _s << endl << flush;
// helpful to use OutputDebugString on windows
#ifdef _WIN32
{
OutputDebugStringA(_s.data());
OutputDebugStringA("\n");
}
#endif
std::cerr << _s << '\n';
}
std::function<void(std::string const&, char const*)> dev::g_logPost = simpleDebugOut;

7
libdevcore/Log.h

@ -44,14 +44,11 @@ public:
};
/// A simple log-output function that prints log messages to stdout.
void simpleDebugOut(std::string const&, char const*);
void simpleDebugOut(std::string const&);
/// The logging system's current verbosity.
extern int g_logVerbosity;
/// The current method that the logging system uses to output the log messages. Defaults to simpleDebugOut().
extern std::function<void(std::string const&, char const*)> g_logPost;
class ThreadContext
{
public:
@ -208,7 +205,7 @@ public:
LogOutputStream(): LogOutputStreamBase(Id::name(), &typeid(Id), Id::verbosity, _AutoSpacing) {}
/// Destructor. Posts the accrued log entry to the g_logPost function.
~LogOutputStream() { if (Id::verbosity <= g_logVerbosity) g_logPost(m_sstr.str(), Id::name()); }
~LogOutputStream() { if (Id::verbosity <= g_logVerbosity) simpleDebugOut(m_sstr.str()); }
LogOutputStream& operator<<(std::string const& _t) { if (Id::verbosity <= g_logVerbosity) { if (_AutoSpacing && m_sstr.str().size() && m_sstr.str().back() != ' ') m_sstr << " "; comment(_t); } return *this; }

Loading…
Cancel
Save