fixed-width formatting on console appender
This commit is contained in:
parent
a792cfaca7
commit
49a83ec7f5
1 changed files with 34 additions and 4 deletions
|
|
@ -12,6 +12,9 @@
|
|||
#include "console_defines.h"
|
||||
#include <fc/io/stdio.hpp>
|
||||
#include <fc/exception/exception.hpp>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
|
||||
|
||||
namespace fc {
|
||||
console_appender::console_appender( const variant& args )
|
||||
|
|
@ -58,19 +61,46 @@ namespace fc {
|
|||
return get_console_color( lc[l] );
|
||||
}
|
||||
void console_appender::log( const log_message& m ) {
|
||||
fc::string message = fc::format_string( m.get_format(), m.get_data() );
|
||||
fc::variant lmsg(m);
|
||||
//fc::string message = fc::format_string( m.get_format(), m.get_data() );
|
||||
//fc::variant lmsg(m);
|
||||
|
||||
FILE* out = stream::std_error ? stderr : stdout;
|
||||
|
||||
fc::string fmt_str = fc::format_string( cfg.format, mutable_variant_object(m.get_context())( "message", message) );
|
||||
//fc::string fmt_str = fc::format_string( cfg.format, mutable_variant_object(m.get_context())( "message", message) );
|
||||
std::stringstream file_line;
|
||||
file_line << m.get_context().get_file() <<":"<<m.get_context().get_line_number() <<" ";
|
||||
|
||||
///////////////
|
||||
std::stringstream line;
|
||||
line << (m.get_context().get_timestamp().time_since_epoch().count() % (1000ll*1000ll*60ll*60))/1000 <<"ms ";
|
||||
line << std::setw( 10 ) << m.get_context().get_thread_name().substr(0,9).c_str() <<" "<<std::setw(20)<<file_line.str();
|
||||
|
||||
auto me = m.get_context().get_method();
|
||||
// strip all leading scopes...
|
||||
if( me.size() )
|
||||
{
|
||||
uint32_t p = 0;
|
||||
for( uint32_t i = 0;i < me.size(); ++i )
|
||||
{
|
||||
if( me[i] == ':' ) p = i;
|
||||
}
|
||||
|
||||
if( me[p] == ':' ) ++p;
|
||||
line << std::setw( 20 ) << m.get_context().get_method().substr(p,20).c_str() <<" ";
|
||||
}
|
||||
line << "] ";
|
||||
fc::string message = fc::format_string( m.get_format(), m.get_data() );
|
||||
line << message;//.c_str();
|
||||
//
|
||||
//
|
||||
|
||||
|
||||
fc::unique_lock<boost::mutex> lock(log_mutex());
|
||||
#ifndef WIN32
|
||||
if(isatty(fileno(out))) fprintf( out, "\r%s", get_color( m.get_context().get_log_level() ) );
|
||||
#endif
|
||||
|
||||
fprintf( out, "%s", fmt_str.c_str() );
|
||||
fprintf( out, "%s", line.str().c_str()); //fmt_str.c_str() );
|
||||
|
||||
#ifndef WIN32
|
||||
if(isatty(fileno(out))) fprintf( out, "\r%s", CONSOLE_DEFAULT );
|
||||
|
|
|
|||
Loading…
Reference in a new issue