Browse Source

More colourful logging.

cl-refactor
Gav Wood 10 years ago
parent
commit
6aff7a03b1
  1. 7
      alethzero/MainWin.cpp
  2. 66
      eth/main.cpp
  3. 25
      libdevcore/Log.cpp
  4. 40
      libdevcore/Log.h
  5. 110
      libdevcore/Terminal.h
  6. 4
      libethereum/Executive.cpp
  7. 9
      libp2p/Session.cpp
  8. 4
      test/vm.cpp

7
alethzero/MainWin.cpp

@ -116,6 +116,11 @@ QString contentsOfQResource(string const& res)
Address c_newConfig = Address("c6d9d2cd449a754c494264e1809c50e34d64562b"); Address c_newConfig = Address("c6d9d2cd449a754c494264e1809c50e34d64562b");
//Address c_nameReg = Address("ddd1cea741d548f90d86fb87a3ae6492e18c03a1"); //Address c_nameReg = Address("ddd1cea741d548f90d86fb87a3ae6492e18c03a1");
static QString filterOutTerminal(QString _s)
{
return _s.replace(QRegExp("\x1b\\[(\\d;)?\\d+m"), "");
}
Main::Main(QWidget *parent) : Main::Main(QWidget *parent) :
QMainWindow(parent), QMainWindow(parent),
ui(new Ui::Main), ui(new Ui::Main),
@ -130,7 +135,7 @@ Main::Main(QWidget *parent) :
{ {
simpleDebugOut(s, c); simpleDebugOut(s, c);
m_logLock.lock(); m_logLock.lock();
m_logHistory.append(QString::fromStdString(s) + "\n"); m_logHistory.append(filterOutTerminal(QString::fromStdString(s)) + "\n");
m_logChanged = true; m_logChanged = true;
m_logLock.unlock(); m_logLock.unlock();
// ui->log->addItem(QString::fromStdString(s)); // ui->log->addItem(QString::fromStdString(s));

66
eth/main.cpp

@ -405,6 +405,72 @@ void doFarm(MinerType _m, string const& _remote, unsigned _recheckPeriod)
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
cout << "\x1b[30mEthBlack\x1b[0m" << endl;
cout << "\x1b[90mEthCoal\x1b[0m" << endl;
cout << "\x1b[37mEthGray\x1b[0m" << endl;
cout << "\x1b[97mEthWhite\x1b[0m" << endl;
cout << "\x1b[31mEthRed\x1b[0m" << endl;
cout << "\x1b[32mEthGreen\x1b[0m" << endl;
cout << "\x1b[33mEthYellow\x1b[0m" << endl;
cout << "\x1b[34mEthBlue\x1b[0m" << endl;
cout << "\x1b[35mEthPurple\x1b[0m" << endl;
cout << "\x1b[36mEthCyan\x1b[0m" << endl;
// High Intensity
cout << "\x1b[91mEthRedI\x1b[0m" << endl;
cout << "\x1b[92mEthLime\x1b[0m" << endl;
cout << "\x1b[93mEthYellowI\x1b[0m" << endl;
cout << "\x1b[94mEthBlueI\x1b[0m" << endl;
cout << "\x1b[95mEthPurpleI\x1b[0m" << endl;
cout << "\x1b[96mEthCyanI\x1b[0m" << endl;
// Bold
cout << "\x1b[1;30mEthBlackB\x1b[0m" << endl;
cout << "\x1b[1;90mEthCoalB\x1b[0m" << endl;
cout << "\x1b[1;37mEthGrayB\x1b[0m" << endl;
cout << "\x1b[1;97mEthWhiteB\x1b[0m" << endl;
cout << "\x1b[1;31mEthRedB\x1b[0m" << endl;
cout << "\x1b[1;32mEthGreenB\x1b[0m" << endl;
cout << "\x1b[1;33mEthYellowB\x1b[0m" << endl;
cout << "\x1b[1;34mEthBlueB\x1b[0m" << endl;
cout << "\x1b[1;35mEthPurpleB\x1b[0m" << endl;
cout << "\x1b[1;36mEthCyanB\x1b[0m" << endl;
// Bold High Intensity
cout << "\x1b[1;91mEthRedBI\x1b[0m" << endl;
cout << "\x1b[1;92mEthGreenBI\x1b[0m" << endl;
cout << "\x1b[1;93mEthYellowBI\x1b[0m" << endl;
cout << "\x1b[1;94mEthBlueBI\x1b[0m" << endl;
cout << "\x1b[1;95mEthPurpleBI\x1b[0m" << endl;
cout << "\x1b[1;96mEthCyanBI\x1b[0m" << endl;
// Background
cout << "\x1b[40mEthBlackOn\x1b[0m" << endl;
cout << "\x1b[100mEthCoalOn\x1b[0m" << endl;
cout << "\x1b[47mEthGrayOn\x1b[0m" << endl;
cout << "\x1b[107mEthWhiteOn\x1b[0m" << endl;
cout << "\x1b[41mEthRedOn\x1b[0m" << endl;
cout << "\x1b[42mEthGreenOn\x1b[0m" << endl;
cout << "\x1b[43mEthYellowOn\x1b[0m" << endl;
cout << "\x1b[44mEthBlueOn\x1b[0m" << endl;
cout << "\x1b[45mEthPurpleOn\x1b[0m" << endl;
cout << "\x1b[46mEthCyanOn\x1b[0m" << endl;
// High Intensity backgrounds
cout << "\x1b[101mEthRedOnI\x1b[0m" << endl;
cout << "\x1b[102mEthGreenOnI\x1b[0m" << endl;
cout << "\x1b[103mEthYellowOnI\x1b[0m" << endl;
cout << "\x1b[104mEthBlueOnI\x1b[0m" << endl;
cout << "\x1b[105mEthPurpleOnI\x1b[0m" << endl;
cout << "\x1b[106mEthCyanOnI\x1b[0m" << endl;
// Underline
cout << "\x1b[4;30mEthBlackU\x1b[0m" << endl;
cout << "\x1b[4;31mEthRedU\x1b[0m" << endl;
cout << "\x1b[4;32mEthGreenU\x1b[0m" << endl;
cout << "\x1b[4;33mEthYellowU\x1b[0m" << endl;
cout << "\x1b[4;34mEthBlueU\x1b[0m" << endl;
cout << "\x1b[4;35mEthPurpleU\x1b[0m" << endl;
cout << "\x1b[4;36mEthCyanU\x1b[0m" << endl;
cout << "\x1b[4;37mEthWhiteU\x1b[0m" << endl;
// Init defaults // Init defaults
Defaults::get(); Defaults::get();

25
libdevcore/Log.cpp

@ -28,10 +28,35 @@
using namespace std; using namespace std;
using namespace dev; using namespace dev;
//⊳⊲◀▶■▣▢□▷◁▧▨▩▲◆◉◈◇◎●◍◌○◼☑☒☎☢☣☰☀♽♥♠✩✭❓✔✓✖✕✘✓✔✅⚒⚡⦸⬌∅⁕«««»»»
// Logging // Logging
int dev::g_logVerbosity = 5; int dev::g_logVerbosity = 5;
map<type_info const*, bool> dev::g_logOverride; map<type_info const*, bool> dev::g_logOverride;
const char* LogChannel::name() { return EthGray "···" EthReset; }
const char* LeftChannel::name() { return EthNavy "◀▬▬" EthReset; }
const char* RightChannel::name() { return EthGreen "▬▬▶" EthReset; }
const char* WarnChannel::name() { return EthOnRed EthBlackBold "✘✘✘" EthReset; }
const char* NoteChannel::name() { return EthGreen "" EthReset; }
const char* DebugChannel::name() { return EthWhite "" EthReset; }
LogOutputStreamBase::LogOutputStreamBase(char const* _id, std::type_info const* _info, unsigned _v)
{
auto it = g_logOverride.find(_info);
if ((it != g_logOverride.end() && it->second == true) || (it == g_logOverride.end() && (int)_v <= g_logVerbosity))
{
time_t rawTime = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
char buf[24];
if (strftime(buf, 24, "%X", localtime(&rawTime)) == 0)
buf[0] = '\0'; // empty if case strftime fails
static char const* c_begin = EthWhite " [ " EthReset EthCoalBold;
static char const* c_sep = EthReset EthWhite " | " EthReset EthCoalBold;
static char const* c_end = EthReset EthWhite " ] " EthReset;
m_sstr << _id << c_begin << buf << c_sep << getThreadName() << ThreadContext::join(c_sep) << c_end;
}
}
/// Associate a name with each thread for nice logging. /// Associate a name with each thread for nice logging.
struct ThreadLocalLogName struct ThreadLocalLogName
{ {

40
libdevcore/Log.h

@ -75,42 +75,36 @@ std::string getThreadName();
/// The default logging channels. Each has an associated verbosity and three-letter prefix (name() ). /// The default logging channels. Each has an associated verbosity and three-letter prefix (name() ).
/// Channels should inherit from LogChannel and define name() and verbosity. /// Channels should inherit from LogChannel and define name() and verbosity.
struct LogChannel { static const char* name() { return " "; } static const int verbosity = 1; }; struct LogChannel { static const char* name(); static const int verbosity = 1; };
struct LeftChannel: public LogChannel { static const char* name() { return "<<<"; } }; struct LeftChannel: public LogChannel { static const char* name(); };
struct RightChannel: public LogChannel { static const char* name() { return ">>>"; } }; struct RightChannel: public LogChannel { static const char* name(); };
struct WarnChannel: public LogChannel { static const char* name() { return EthWhiteOn EthBlackB "!!!" EthReset; } static const int verbosity = 0; }; struct WarnChannel: public LogChannel { static const char* name(); static const int verbosity = 0; };
struct NoteChannel: public LogChannel { static const char* name() { return "***"; } }; struct NoteChannel: public LogChannel { static const char* name(); };
struct DebugChannel: public LogChannel { static const char* name() { return EthWhiteB "---" EthReset; } static const int verbosity = 0; }; struct DebugChannel: public LogChannel { static const char* name(); static const int verbosity = 0; };
class LogOutputStreamBase
{
public:
LogOutputStreamBase(char const* _id, std::type_info const* _info, unsigned _v);
protected:
std::stringstream m_sstr; ///< The accrued log entry.
};
/// Logging class, iostream-like, that can be shifted to. /// Logging class, iostream-like, that can be shifted to.
template <class Id, bool _AutoSpacing = true> template <class Id, bool _AutoSpacing = true>
class LogOutputStream class LogOutputStream: private LogOutputStreamBase
{ {
public: public:
/// Construct a new object. /// Construct a new object.
/// If _term is true the the prefix info is terminated with a ']' character; if not it ends only with a '|' character. /// If _term is true the the prefix info is terminated with a ']' character; if not it ends only with a '|' character.
LogOutputStream(bool _term = true) LogOutputStream(): LogOutputStreamBase(Id::name(), &typeid(Id), Id::verbosity) {}
{
std::type_info const* i = &typeid(Id);
auto it = g_logOverride.find(i);
if ((it != g_logOverride.end() && it->second == true) || (it == g_logOverride.end() && Id::verbosity <= g_logVerbosity))
{
time_t rawTime = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
char buf[24];
if (strftime(buf, 24, "%X", localtime(&rawTime)) == 0)
buf[0] = '\0'; // empty if case strftime fails
m_sstr << Id::name() << EthBlue " [ " EthBlueI << buf << EthBlue " | " EthCyan << getThreadName() << ThreadContext::join(EthBlue " | " EthPurple) << (_term ? EthBlue " ] " : "") << EthReset;
}
}
/// Destructor. Posts the accrued log entry to the g_logPost function. /// 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) g_logPost(m_sstr.str(), Id::name()); }
/// Shift arbitrary data to the log. Spaces will be added between items as required. /// Shift arbitrary data to the log. Spaces will be added between items as required.
template <class T> LogOutputStream& operator<<(T const& _t) { if (Id::verbosity <= g_logVerbosity) { if (_AutoSpacing && m_sstr.str().size() && m_sstr.str().back() != ' ') m_sstr << " "; m_sstr << _t; } return *this; } template <class T> LogOutputStream& operator<<(T const& _t) { if (Id::verbosity <= g_logVerbosity) { if (_AutoSpacing && m_sstr.str().size() && m_sstr.str().back() != ' ') m_sstr << " "; m_sstr << _t; } return *this; }
private:
std::stringstream m_sstr; ///< The accrued log entry.
}; };
// Simple cout-like stream objects for accessing common log channels. // Simple cout-like stream objects for accessing common log channels.

110
libdevcore/Terminal.h

@ -52,7 +52,7 @@ namespace con
// High Intensity // High Intensity
#define EthCoal "" // Black #define EthCoal "" // Black
#define EthRedI "" // Red #define EthRedI "" // Red
#define EthGreenI "" // Green #define EthLime "" // Green
#define EthYellowI "" // Yellow #define EthYellowI "" // Yellow
#define EthBlueI "" // Blue #define EthBlueI "" // Blue
#define EthPurpleI "" // Purple #define EthPurpleI "" // Purple
@ -88,67 +88,63 @@ namespace con
#define EthCoal "\x1b[90m" // Black #define EthCoal "\x1b[90m" // Black
#define EthGray "\x1b[37m" // White #define EthGray "\x1b[37m" // White
#define EthWhite "\x1b[97m" // White #define EthWhite "\x1b[97m" // White
#define EthRed "\x1b[31m" // Red #define EthMaroon "\x1b[31m" // Red
#define EthRed "\x1b[91m" // Red
#define EthGreen "\x1b[32m" // Green #define EthGreen "\x1b[32m" // Green
#define EthYellow "\x1b[33m" // Yellow #define EthLime "\x1b[92m" // Green
#define EthBlue "\x1b[34m" // Blue #define EthOrange "\x1b[33m" // Yellow
#define EthPurple "\x1b[35m" // Purple #define EthYellow "\x1b[93m" // Yellow
#define EthCyan "\x1b[36m" // Cyan #define EthNavy "\x1b[34m" // Blue
// High Intensity #define EthBlue "\x1b[94m" // Blue
#define EthRedI "\x1b[91m" // Red #define EthViolet "\x1b[35m" // Purple
#define EthGreenI "\x1b[92m" // Green #define EthPurple "\x1b[95m" // Purple
#define EthYellowI "\x1b[93m" // Yellow #define EthTeal "\x1b[36m" // Cyan
#define EthBlueI "\x1b[94m" // Blue #define EthCyan "\x1b[96m" // Cyan
#define EthPurpleI "\x1b[95m" // Purple
#define EthCyanI "\x1b[96m" // Cyan #define EthBlackBold "\x1b[1;30m" // Black
#define EthCoalBold "\x1b[1;90m" // Black
// Bold #define EthGrayBold "\x1b[1;37m" // White
#define EthBlackB "\x1b[1;30m" // Black #define EthWhiteBold "\x1b[1;97m" // White
#define EthCoalB "\x1b[1;90m" // Black #define EthMaroonBold "\x1b[1;31m" // Red
#define EthGrayB "\x1b[1;37m" // White #define EthRedBold "\x1b[1;91m" // Red
#define EthWhiteB "\x1b[1;97m" // White #define EthGreenBold "\x1b[1;32m" // Green
#define EthRedB "\x1b[1;31m" // Red #define EthLimeBold "\x1b[1;92m" // Green
#define EthGreenB "\x1b[1;32m" // Green #define EthOrangeBold "\x1b[1;33m" // Yellow
#define EthYellowB "\x1b[1;33m" // Yellow #define EthYellowBold "\x1b[1;93m" // Yellow
#define EthBlueB "\x1b[1;34m" // Blue #define EthNavyBold "\x1b[1;34m" // Blue
#define EthPurpleB "\x1b[1;35m" // Purple #define EthBlueBold "\x1b[1;94m" // Blue
#define EthCyanB "\x1b[1;36m" // Cyan #define EthVioletBold "\x1b[1;35m" // Purple
// Bold High Intensity #define EthPurpleBold "\x1b[1;95m" // Purple
#define EthRedBI "\x1b[1;91m" // Red #define EthTealBold "\x1b[1;36m" // Cyan
#define EthGreenBI "\x1b[1;92m" // Green #define EthCyanBold "\x1b[1;96m" // Cyan
#define EthYellowBI "\x1b[1;93m" // Yellow
#define EthBlueBI "\x1b[1;94m" // Blue
#define EthPurpleBI "\x1b[1;95m" // Purple
#define EthCyanBI "\x1b[1;96m" // Cyan
// Background // Background
#define EthBlackOn "\x1b[40m" // Black #define EthOnBlack "\x1b[40m" // Black
#define EthCoalOn "\x1b[100m" // Black #define EthOnCoal "\x1b[100m" // Black
#define EthGrayOn "\x1b[47m" // White #define EthOnGray "\x1b[47m" // White
#define EthWhiteOn "\x1b[107m" // White #define EthOnWhite "\x1b[107m" // White
#define EthRedOn "\x1b[41m" // Red #define EthOnMaroon "\x1b[41m" // Red
#define EthGreenOn "\x1b[42m" // Green #define EthOnRed "\x1b[101m" // Red
#define EthYellowOn "\x1b[43m" // Yellow #define EthOnGreen "\x1b[42m" // Green
#define EthBlueOn "\x1b[44m" // Blue #define EthOnLime "\x1b[102m" // Green
#define EthPurpleOn "\x1b[45m" // Purple #define EthOnOrange "\x1b[43m" // Yellow
#define EthCyanOn "\x1b[46m" // Cyan #define EthOnYellow "\x1b[103m" // Yellow
// High Intensity backgrounds #define EthOnNavy "\x1b[44m" // Blue
#define EthRedOnI "\x1b[101m" // Red #define EthOnBlue "\x1b[104m" // Blue
#define EthGreenOnI "\x1b[102m" // Green #define EthOnViolet "\x1b[45m" // Purple
#define EthYellowOnI "\x1b[103m" // Yellow #define EthOnPurple "\x1b[105m" // Purple
#define EthBlueOnI "\x1b[104m" // Blue #define EthOnTeal "\x1b[46m" // Cyan
#define EthPurpleOnI "\x1b[105m" // Purple #define EthOnCyan "\x1b[106m" // Cyan
#define EthCyanOnI "\x1b[106m" // Cyan
// Underline // Underline
#define EthBlackU "\x1b[4;30m" // Black #define EthBlackUnder "\x1b[4;30m" // Black
#define EthRedU "\x1b[4;31m" // Red #define EthGrayUnder "\x1b[4;37m" // White
#define EthGreenU "\x1b[4;32m" // Green #define EthMaroonUnder "\x1b[4;31m" // Red
#define EthYellowU "\x1b[4;33m" // Yellow #define EthGreenUnder "\x1b[4;32m" // Green
#define EthBlueU "\x1b[4;34m" // Blue #define EthOrangeUnder "\x1b[4;33m" // Yellow
#define EthPurpleU "\x1b[4;35m" // Purple #define EthNavyUnder "\x1b[4;34m" // Blue
#define EthCyanU "\x1b[4;36m" // Cyan #define EthVioletUnder "\x1b[4;35m" // Purple
#define EthWhiteU "\x1b[4;37m" // White #define EthTealUnder "\x1b[4;36m" // Cyan
#endif #endif

4
libethereum/Executive.cpp

@ -199,8 +199,8 @@ OnOpFunc Executive::simpleTrace()
o << " STORAGE" << endl; o << " STORAGE" << endl;
for (auto const& i: ext.state().storage(ext.myAddress)) for (auto const& i: ext.state().storage(ext.myAddress))
o << showbase << hex << i.first << ": " << i.second << endl; o << showbase << hex << i.first << ": " << i.second << endl;
dev::LogOutputStream<VMTraceChannel, false>(true) << o.str(); dev::LogOutputStream<VMTraceChannel, false>() << o.str();
dev::LogOutputStream<VMTraceChannel, false>(false) << " | " << dec << ext.depth << " | " << ext.myAddress << " | #" << steps << " | " << hex << setw(4) << setfill('0') << vm.curPC() << " : " << instructionInfo(inst).name << " | " << dec << vm.gas() << " | -" << dec << gasCost << " | " << newMemSize << "x32" << " ]"; dev::LogOutputStream<VMTraceChannel, false>() << " < " << dec << ext.depth << " : " << ext.myAddress << " : #" << steps << " : " << hex << setw(4) << setfill('0') << vm.curPC() << " : " << instructionInfo(inst).name << " : " << dec << vm.gas() << " : -" << dec << gasCost << " : " << newMemSize << "x32" << " >";
}; };
} }

9
libp2p/Session.cpp

@ -48,7 +48,8 @@ Session::Session(Host* _s, RLPXFrameIO* _io, std::shared_ptr<Peer> const& _n, Pe
Session::~Session() Session::~Session()
{ {
ThreadContext tc(info().id.abridged() + " | " + info().clientVersion); ThreadContext tc(info().id.abridged());
ThreadContext tc2(info().clientVersion);
clog(NetMessageSummary) << "Closing peer session :-("; clog(NetMessageSummary) << "Closing peer session :-(";
m_peer->m_lastConnected = m_peer->m_lastAttempted - chrono::seconds(1); m_peer->m_lastConnected = m_peer->m_lastAttempted - chrono::seconds(1);
@ -323,7 +324,8 @@ void Session::write()
auto self(shared_from_this()); auto self(shared_from_this());
ba::async_write(m_socket, ba::buffer(bytes), [this, self](boost::system::error_code ec, std::size_t /*length*/) ba::async_write(m_socket, ba::buffer(bytes), [this, self](boost::system::error_code ec, std::size_t /*length*/)
{ {
ThreadContext tc(info().id.abridged() + " | " + info().clientVersion); ThreadContext tc(info().id.abridged());
ThreadContext tc2(info().clientVersion);
// must check queue, as write callback can occur following dropped() // must check queue, as write callback can occur following dropped()
if (ec) if (ec)
{ {
@ -397,7 +399,8 @@ void Session::doRead()
auto self(shared_from_this()); auto self(shared_from_this());
ba::async_read(m_socket, boost::asio::buffer(m_data, h256::size), [this,self](boost::system::error_code ec, std::size_t length) ba::async_read(m_socket, boost::asio::buffer(m_data, h256::size), [this,self](boost::system::error_code ec, std::size_t length)
{ {
ThreadContext tc(info().id.abridged() + " | " + info().clientVersion); ThreadContext tc(info().id.abridged());
ThreadContext tc2(info().clientVersion);
if (ec && ec.category() != boost::asio::error::get_misc_category() && ec.value() != boost::asio::error::eof) if (ec && ec.category() != boost::asio::error::get_misc_category() && ec.value() != boost::asio::error::eof)
{ {
clog(NetWarn) << "Error reading: " << ec.message(); clog(NetWarn) << "Error reading: " << ec.message();

4
test/vm.cpp

@ -261,8 +261,8 @@ eth::OnOpFunc FakeExtVM::simpleTrace()
for (auto const& i: std::get<2>(ext.addresses.find(ext.myAddress)->second)) for (auto const& i: std::get<2>(ext.addresses.find(ext.myAddress)->second))
o << std::showbase << std::hex << i.first << ": " << i.second << std::endl; o << std::showbase << std::hex << i.first << ": " << i.second << std::endl;
dev::LogOutputStream<eth::VMTraceChannel, false>(true) << o.str(); dev::LogOutputStream<eth::VMTraceChannel, false>() << o.str();
dev::LogOutputStream<eth::VMTraceChannel, false>(false) << " | " << std::dec << ext.depth << " | " << ext.myAddress << " | #" << steps << " | " << std::hex << std::setw(4) << std::setfill('0') << vm.curPC() << " : " << instructionInfo(inst).name << " | " << std::dec << vm.gas() << " | -" << std::dec << gasCost << " | " << newMemSize << "x32" << " ]"; dev::LogOutputStream<eth::VMTraceChannel, false>() << " | " << std::dec << ext.depth << " | " << ext.myAddress << " | #" << steps << " | " << std::hex << std::setw(4) << std::setfill('0') << vm.curPC() << " : " << instructionInfo(inst).name << " | " << std::dec << vm.gas() << " | -" << std::dec << gasCost << " | " << newMemSize << "x32" << " ]";
/*creates json stack trace*/ /*creates json stack trace*/
if (eth::VMTraceChannel::verbosity <= g_logVerbosity) if (eth::VMTraceChannel::verbosity <= g_logVerbosity)

Loading…
Cancel
Save