Log the names of tasks to the log file (now contains thread_name:task_name}

This commit is contained in:
Eric Frias 2014-08-24 18:33:05 -04:00
parent 198d858d59
commit 27096f15a7
5 changed files with 18 additions and 1 deletions

View file

@ -68,6 +68,7 @@ namespace fc
uint64_t get_line_number()const;
string get_method()const;
string get_thread_name()const;
string get_task_name()const;
string get_host_name()const;
time_point get_timestamp()const;
log_level get_log_level()const;

View file

@ -32,6 +32,8 @@ namespace fc {
*/
void set_name( const string& n );
const char* current_task_desc() const;
/**
* @brief print debug info about the state of every context / promise.
*

View file

@ -192,7 +192,7 @@ namespace fc {
std::stringstream line;
//line << (m.get_context().get_timestamp().time_since_epoch().count() % (1000ll*1000ll*60ll*60))/1000 <<"ms ";
line << std::string(m.get_context().get_timestamp()) << " ";
line << std::setw( 10 ) << m.get_context().get_thread_name().substr(0,9).c_str() <<" ";
line << std::setw( 21 ) << (m.get_context().get_thread_name().substr(0,9) + string(":") + m.get_context().get_task_name()).c_str() <<" ";
auto me = m.get_context().get_method();
// strip all leading scopes...

View file

@ -20,6 +20,7 @@ namespace fc
uint64_t line;
string method;
string thread_name;
string task_name;
string hostname;
string context;
time_point timestamp;
@ -53,6 +54,8 @@ namespace fc
my->method = method;
my->timestamp = time_point::now();
my->thread_name = fc::thread::current().name();
const char* current_task_desc = fc::thread::current().current_task_desc();
my->task_name = current_task_desc ? current_task_desc : "?unnamed?";
}
log_context::log_context( const variant& v )
@ -65,6 +68,8 @@ namespace fc
my->method = obj["method"].as_string();
my->hostname = obj["hostname"].as_string();
my->thread_name = obj["thread_name"].as_string();
if (obj.contains("task_name"))
my->task_name = obj["task_name"].as_string();
my->timestamp = obj["timestamp"].as<time_point>();
if( obj.contains( "context" ) )
my->context = obj["context"].as<string>();
@ -149,6 +154,7 @@ namespace fc
uint64_t log_context::get_line_number()const { return my->line; }
string log_context::get_method()const { return my->method; }
string log_context::get_thread_name()const { return my->thread_name; }
string log_context::get_task_name()const { return my->task_name; }
string log_context::get_host_name()const { return my->hostname; }
time_point log_context::get_timestamp()const { return my->timestamp; }
log_level log_context::get_log_level()const{ return my->level; }

View file

@ -123,6 +123,14 @@ namespace fc {
}
const string& thread::name()const { return my->name; }
void thread::set_name( const fc::string& n ) { my->name = n; }
const char* thread::current_task_desc() const
{
if (my->current && my->current->cur_task)
return my->current->cur_task->get_desc();
return NULL;
}
void thread::debug( const fc::string& d ) { /*my->debug(d);*/ }
void thread::quit() {