43 static map<type_info const*, bool> s_logOverride;
48 if (s_logOverride.count(_ch))
49 return s_logOverride[_ch];
53 LogOverrideAux::LogOverrideAux(std::type_info
const* _ch,
bool _value):
57 m_old = s_logOverride.count(_ch) ? (int)s_logOverride[_ch] :
c_null;
58 s_logOverride[
m_ch] = _value;
65 s_logOverride.erase(
m_ch);
89 m_autospacing(_autospacing),
93 auto it = s_logOverride.find(_info);
94 if ((it != s_logOverride.end() && it->second ==
true) || (it == s_logOverride.end() && (int)_v <=
g_logVerbosity))
96 time_t rawTime = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
97 unsigned ms = chrono::duration_cast<chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).
count() % 1000;
99 if (strftime(buf, 24,
"%X", localtime(&rawTime)) == 0)
101 static char const* c_begin =
" " EthViolet;
104 static char const* c_end =
EthReset " ";
105 m_sstr << _id << c_begin << buf <<
"." << setw(3) << setfill(
'0') << ms;
114 boost::thread_specific_ptr<std::string>
m_name;
122 void push(std::string
const& _name)
124 if (!m_contexts.get())
125 m_contexts.reset(
new vector<string>);
126 m_contexts->push_back(_name);
131 m_contexts->pop_back();
134 string join(
string const& _prior)
137 if (m_contexts.get())
138 for (
auto const& i: *m_contexts)
143 boost::thread_specific_ptr<std::vector<std::string>>
m_contexts;
152 g_logThreadContext.
push(_n);
157 g_logThreadContext.
pop();
162 return g_logThreadContext.
join(_prior);
167 extern "C" __declspec(dllimport)
void __stdcall OutputDebugStringA(
const char* lpOutputString);
175 #if defined(__GLIBC__) || defined(__APPLE__) 177 pthread_getname_np(pthread_self(), buffer, 127);
189 #if defined(__GLIBC__) 190 pthread_setname_np(pthread_self(), _n.c_str());
191 #elif defined(__APPLE__) 192 pthread_setname_np(_n.c_str());
204 cerr << _s << endl << flush;
209 OutputDebugStringA(_s.data());
210 OutputDebugStringA(
"\n");
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
std::type_info const * m_ch
ThreadLocalLogContext g_logThreadContext
void simpleDebugOut(std::string const &, char const *)
A simple log-output function that prints log messages to stdout.
ThreadLocalLogName(std::string const &_name)
void push(std::string const &_name)
bool isChannelVisible(std::type_info const *_ch, bool _default)
std::hash for asio::adress
static const char * name()
Simple lock that waits for release without making context switch.
std::stringstream m_sstr
The accrued log entry.
Associate a name with each thread for nice logging.
ThreadLocalLogName g_logThreadName("main")
static const char * name()
LogOutputStreamBase(char const *_id, std::type_info const *_info, unsigned _v, bool _autospacing)
std::lock_guard< std::mutex > Guard
std::function< void(std::string const &, char const *)> g_logPost
The current method that the logging system uses to output the log messages. Defaults to simpleDebugOu...
void setThreadName(std::string const &_n)
Set the current thread's log name.
std::string getThreadName()
Set the current thread's log name.
std::lock_guard< SpinLock > SpinGuard
static const char * name()
static std::string join(std::string const &_prior)
int g_logVerbosity
The logging system's current verbosity.
boost::thread_specific_ptr< std::vector< std::string > > m_contexts
static void push(std::string const &_n)
static const char * name()
static const char * name()
string join(string const &_prior)
Associate a name with each thread for nice logging.
static const char * name()
boost::thread_specific_ptr< std::string > m_name
static const char * name()