add more debug log :-/

JSON-143
Roker 2020-05-29 11:15:37 +02:00
parent 6a432db19a
commit 9bb80e2fab
4 changed files with 22 additions and 8 deletions

View File

@ -72,6 +72,8 @@ struct EventListenerValue
utility::locked_queue<std::string> Q;
};
static std::hash<std::thread::id> hash_tid;
} // end of anonymous namespace
@ -145,8 +147,10 @@ struct JsonAdapter::Internal
const std::string request_r = js::write(request);
Lock L(_mtx);
Log << Logger::Debug << "makeAndDeliverRequest to " << eventListener.size() << " listener(s).";
for(auto& e : eventListener)
{
Log << Logger::Debug << " ~~~ [" << e.first << Logger::thread_id(hash_tid(e.first)) << "] has " << e.second.Q.size() << " old events waiting.";
e.second.Q.push_back(request_r);
}
}
@ -461,7 +465,7 @@ js::Array JsonAdapter::pollForEvents(unsigned timeout_seconds)
}else{
// block until there is at least one element or timeout
std::string event;
const bool success = el.Q.try_pop_front( event, std::chrono::steady_clock::now() + std::chrono::seconds(timeout_seconds) );
const bool success = el.Q.try_pop_front( event, std::chrono::seconds(timeout_seconds) );
if(success)
{
arr.emplace_back( std::move(event) );

View File

@ -27,8 +27,8 @@ Logger& Log()
js::Object ret;
ret.emplace_back( "jsonrpc", "2.0" );
ret.emplace_back( "id" , id );
ret.emplace_back( "result" , result );
ret.emplace_back( "thread_id", Logger::thread_id() );
ret.emplace_back( "result" , result );
DEBUG_OUT(Log(), "make_result(): result: " + js::write(result) );
return ret;
@ -49,9 +49,9 @@ Logger& Log()
js::Object ret;
ret.emplace_back( "jsonrpc", "2.0" );
ret.emplace_back( "error" , err_obj );
ret.emplace_back( "id" , id );
ret.emplace_back( "thread_id", Logger::thread_id() );
ret.emplace_back( "error" , err_obj );
return ret;
}
@ -61,9 +61,9 @@ js::Object make_request(const std::string& functionName, const js::Array& parame
{
js::Object request;
request.emplace_back( "method", functionName );
request.emplace_back( "params", parameters );
request.emplace_back( "request_nr", ++request_nr );
request.emplace_back( "thread_id", Logger::thread_id() );
request.emplace_back( "params", parameters );
return request;
}

View File

@ -421,16 +421,21 @@ static const unsigned thread_alph_len = thread_alphabet.size(); // shall be a pr
static std::hash<std::thread::id> hash_tid;
// create a three-digit base37 string of the current thread ID for easy grepping and filtering:
std::string Logger::thread_id()
std::string Logger::thread_id(unsigned long long id)
{
char buf[8] = { ' ', '\302', '\266', '?', '?', '?', ' ' };
unsigned long long id = hash_tid(std::this_thread::get_id());
buf[3] = thread_alphabet.at( id % thread_alph_len); id /= thread_alph_len;
buf[4] = thread_alphabet.at( id % thread_alph_len); id /= thread_alph_len;
buf[5] = thread_alphabet.at( id % thread_alph_len); id /= thread_alph_len;
return std::string(buf, buf+7);
}
std::string Logger::thread_id()
{
const unsigned long long id = hash_tid(std::this_thread::get_id());
return thread_id(id);
}
void LoggerS::log(Logger::Severity s, const std::string& logline)
{

View File

@ -124,10 +124,15 @@ public:
Logger(const Logger&) = delete;
void operator=(const Logger&) = delete;
// returns the thread_id hash for the current thread
static
std::string thread_id();
// returns the thread_id hash for the given thread id
static
std::string thread_id(unsigned long long id);
class Stream
{
public: