diff --git a/include/fc/log/console_appender.hpp b/include/fc/log/console_appender.hpp index c15fcf089..72af377b1 100644 --- a/include/fc/log/console_appender.hpp +++ b/include/fc/log/console_appender.hpp @@ -3,12 +3,12 @@ #include #include -namespace fc +namespace fc { - class console_appender : public appender + class console_appender : public appender { public: - struct color + struct color { enum type { red, @@ -24,9 +24,9 @@ namespace fc struct stream { enum type { std_out, std_error }; }; - struct level_color + struct level_color { - level_color( log_level l=log_level::all, + level_color( log_level l=log_level::all, color::type c=color::console_default ) :level(l),color(c){} @@ -34,10 +34,10 @@ namespace fc console_appender::color::type color; }; - struct config + struct config { config() - :format( "${timestamp} ${thread_name} ${context} ${file}:${line} ${method} ${level}] ${message}" ), + :format( "${timestamp} ${context} ${file}:${line} ${method} ${level}] ${message}" ), stream(console_appender::stream::std_error),flush(true){} fc::string format; @@ -53,8 +53,8 @@ namespace fc ~console_appender(); virtual void log( const log_message& m ); - - void print( const std::string& text_to_print, + + void print( const std::string& text_to_print, color::type text_color = color::console_default ); void configure( const config& cfg ); diff --git a/src/log/console_appender.cpp b/src/log/console_appender.cpp index c012743f8..870094aeb 100644 --- a/src/log/console_appender.cpp +++ b/src/log/console_appender.cpp @@ -27,7 +27,7 @@ namespace fc { #endif }; - console_appender::console_appender( const variant& args ) + console_appender::console_appender( const variant& args ) :my(new impl) { configure( args.as() ); @@ -66,7 +66,7 @@ namespace fc { #ifdef WIN32 static WORD #else - static const char* + static const char* #endif get_console_color(console_appender::color::type t ) { switch( t ) { @@ -100,7 +100,7 @@ namespace fc { /////////////// std::stringstream line; line << (m.get_context().get_timestamp().time_since_epoch().count() % (1000ll*1000ll*60ll*60))/1000 <<"ms "; - line << std::setw( 10 ) << std::left << m.get_context().get_thread_name().substr(0,9).c_str() <<" "<console_handle != INVALID_HANDLE_VALUE) diff --git a/src/log/file_appender.cpp b/src/log/file_appender.cpp index 85b69c61b..70d2ec87e 100644 --- a/src/log/file_appender.cpp +++ b/src/log/file_appender.cpp @@ -131,7 +131,7 @@ namespace fc { }; file_appender::config::config(const fc::path& p) : - format( "${timestamp} ${thread_name} ${context} ${file}:${line} ${method} ${level}] ${message}" ), + format( "${timestamp} ${context} ${file}:${line} ${method} ${level}] ${message}" ), filename(p), flush(true), rotate(false) @@ -162,7 +162,7 @@ namespace fc { std::stringstream line; //line << (m.get_context().get_timestamp().time_since_epoch().count() % (1000ll*1000ll*60ll*60))/1000 <<"ms "; line << string(m.get_context().get_timestamp()) << " "; - line << std::setw( 21 ) << (m.get_context().get_thread_name().substr(0,9) + string(":") + m.get_context().get_task_name()).c_str() << " "; + line << std::setw( 21 ) << (m.get_context().get_task_name()).c_str() << " "; string method_name = m.get_context().get_method(); // strip all leading scopes... diff --git a/src/log/gelf_appender.cpp b/src/log/gelf_appender.cpp index b88387c69..ae7be652d 100644 --- a/src/log/gelf_appender.cpp +++ b/src/log/gelf_appender.cpp @@ -17,7 +17,7 @@ #include #include -namespace fc +namespace fc { class gelf_appender::impl : public retainable @@ -27,7 +27,7 @@ namespace fc optional gelf_endpoint; udp_socket gelf_socket; - impl(const config& c) : + impl(const config& c) : cfg(c) { } @@ -52,7 +52,7 @@ namespace fc } if (!my->gelf_endpoint) { - // couldn't parse as a numeric ip address, try resolving as a DNS name. + // couldn't parse as a numeric ip address, try resolving as a DNS name. // This can yield, so don't do it in the catch block above string::size_type colon_pos = my->cfg.endpoint.find(':'); try @@ -62,7 +62,7 @@ namespace fc string hostname = my->cfg.endpoint.substr( 0, colon_pos ); std::vector endpoints = resolve(hostname, port); if (endpoints.empty()) - FC_THROW_EXCEPTION(unknown_host_exception, "The host name can not be resolved: ${hostname}", + FC_THROW_EXCEPTION(unknown_host_exception, "The host name can not be resolved: ${hostname}", ("hostname", hostname)); my->gelf_endpoint = endpoints.back(); } @@ -95,7 +95,7 @@ namespace fc gelf_message["version"] = "1.1"; gelf_message["host"] = my->cfg.host; gelf_message["short_message"] = format_string(message.get_format(), message.get_data()); - + gelf_message["timestamp"] = context.get_timestamp().time_since_epoch().count() / 1000000.; switch (context.get_log_level()) @@ -124,16 +124,15 @@ namespace fc gelf_message["_line"] = context.get_line_number(); gelf_message["_file"] = context.get_file(); gelf_message["_method_name"] = context.get_method(); - gelf_message["_thread_name"] = context.get_thread_name(); if (!context.get_task_name().empty()) gelf_message["_task_name"] = context.get_task_name(); string gelf_message_as_string = json::to_string(gelf_message); //unsigned uncompressed_size = gelf_message_as_string.size(); gelf_message_as_string = zlib_compress(gelf_message_as_string); - + // graylog2 expects the zlib header to be 0x78 0x9c - // but miniz.c generates 0x78 0x01 (indicating + // but miniz.c generates 0x78 0x01 (indicating // low compression instead of default compression) // so change that here assert(gelf_message_as_string[0] == (char)0x78); @@ -155,16 +154,16 @@ namespace fc // no need to split std::shared_ptr send_buffer(new char[gelf_message_as_string.size()], [](char* p){ delete[] p; }); - memcpy(send_buffer.get(), gelf_message_as_string.c_str(), + memcpy(send_buffer.get(), gelf_message_as_string.c_str(), gelf_message_as_string.size()); - my->gelf_socket.send_to(send_buffer, gelf_message_as_string.size(), + my->gelf_socket.send_to(send_buffer, gelf_message_as_string.size(), *my->gelf_endpoint); } else { // split the message - // we need to generate an 8-byte ID for this message. + // we need to generate an 8-byte ID for this message. // city hash should do uint64_t message_id = city_hash64(gelf_message_as_string.c_str(), gelf_message_as_string.size()); const unsigned header_length = 2 /* magic */ + 8 /* msg id */ + 1 /* seq */ + 1 /* count */; @@ -174,10 +173,10 @@ namespace fc unsigned number_of_packets_sent = 0; while (bytes_sent < gelf_message_as_string.size()) { - unsigned bytes_to_send = std::min((unsigned)gelf_message_as_string.size() - bytes_sent, + unsigned bytes_to_send = std::min((unsigned)gelf_message_as_string.size() - bytes_sent, body_length); - - std::shared_ptr send_buffer(new char[max_payload_size], + + std::shared_ptr send_buffer(new char[max_payload_size], [](char* p){ delete[] p; }); char* ptr = send_buffer.get(); // magic number for chunked message @@ -190,9 +189,9 @@ namespace fc *(unsigned char*)(ptr++) = number_of_packets_sent; *(unsigned char*)(ptr++) = total_number_of_packets; - memcpy(ptr, gelf_message_as_string.c_str() + bytes_sent, + memcpy(ptr, gelf_message_as_string.c_str() + bytes_sent, bytes_to_send); - my->gelf_socket.send_to(send_buffer, header_length + bytes_to_send, + my->gelf_socket.send_to(send_buffer, header_length + bytes_to_send, *my->gelf_endpoint); ++number_of_packets_sent; bytes_sent += bytes_to_send; diff --git a/src/log/log_message.cpp b/src/log/log_message.cpp index 09b68158a..fe5950e2e 100644 --- a/src/log/log_message.cpp +++ b/src/log/log_message.cpp @@ -19,7 +19,6 @@ namespace fc string file; uint64_t line; string method; - string thread_name; string task_name; string hostname; string context; @@ -44,7 +43,7 @@ namespace fc log_context::log_context() :my( std::make_shared() ){} - log_context::log_context( log_level ll, const char* file, uint64_t line, + log_context::log_context( log_level ll, const char* file, uint64_t line, const char* method ) :my( std::make_shared() ) { @@ -53,7 +52,6 @@ namespace fc my->line = line; 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?"; } @@ -67,7 +65,6 @@ namespace fc my->line = obj["line"].as_uint64(); 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(); @@ -77,7 +74,7 @@ namespace fc fc::string log_context::to_string()const { - return my->thread_name + " " + my->file + ":" + fc::to_string(my->line) + " " + my->method; + return my->file + ":" + fc::to_string(my->line) + " " + my->method; } @@ -92,18 +89,18 @@ namespace fc void to_variant( const log_context& l, variant& v ) - { - v = l.to_variant(); + { + v = l.to_variant(); } void from_variant( const variant& l, log_context& c ) - { - c = log_context(l); + { + c = log_context(l); } void from_variant( const variant& l, log_message& c ) - { - c = log_message(l); + { + c = log_message(l); } void to_variant( const log_message& m, variant& v ) { @@ -114,7 +111,7 @@ namespace fc { switch( e ) { - case log_level::all: + case log_level::all: v = "all"; return; case log_level::debug: @@ -136,7 +133,7 @@ namespace fc } void from_variant( const variant& v, log_level& e ) { - try + try { if( v.as_string() == "all" ) e = log_level::all; else if( v.as_string() == "debug" ) e = log_level::debug; @@ -145,7 +142,7 @@ namespace fc else if( v.as_string() == "error" ) e = log_level::error; else if( v.as_string() == "off" ) e = log_level::off; else FC_THROW_EXCEPTION( bad_cast_exception, "Failed to cast from Variant to log_level" ); - } FC_RETHROW_EXCEPTIONS( error, + } FC_RETHROW_EXCEPTIONS( error, "Expected 'all|debug|info|warn|error|off', but got '${variant}'", ("variant",v) ); } @@ -155,7 +152,6 @@ namespace fc string log_context::get_file()const { return my->file; } 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; } @@ -171,10 +167,9 @@ namespace fc ( "line", my->line ) ( "method", my->method ) ( "hostname", my->hostname ) - ( "thread_name", my->thread_name ) ( "timestamp", variant(my->timestamp) ); - if( my->context.size() ) + if( my->context.size() ) o( "context", my->context ); return o;