fix formatting with logging to file
This commit is contained in:
parent
d73ee6a889
commit
383144938e
2 changed files with 28 additions and 10 deletions
|
|
@ -22,11 +22,6 @@ FIND_PACKAGE(Boost 1.51 COMPONENTS thread date_time system filesystem program_op
|
|||
|
||||
if( WIN32 )
|
||||
set( RPCRT4 Rpcrt4 )
|
||||
set( OPENSSL_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/vendor/openssl" )
|
||||
if ( NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/vendor/openssl/lib" )
|
||||
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/vendor/openssl/out32dll" DESTINATION "${CMAKE_CURRENT_SOURCE_DIR}/vendor/openssl/cmakefun")
|
||||
file(RENAME "${CMAKE_CURRENT_SOURCE_DIR}/vendor/openssl/cmakefun/out32dll" "${CMAKE_CURRENT_SOURCE_DIR}/vendor/openssl/lib")
|
||||
endif( NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/vendor/openssl/lib" )
|
||||
endif( WIN32 )
|
||||
|
||||
LINK_DIRECTORIES( ${Boost_LIBRARY_DIRS} )
|
||||
|
|
@ -57,7 +52,6 @@ endif()
|
|||
option( UNITY_BUILD OFF )
|
||||
|
||||
FIND_PACKAGE( OpenSSL )
|
||||
|
||||
include_directories( ${Boost_INCLUDE_DIR} )
|
||||
include_directories( ${OPENSSL_INCLUDE_DIR} )
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@
|
|||
#include <fc/io/fstream.hpp>
|
||||
#include <fc/variant.hpp>
|
||||
#include <fc/reflect/variant.hpp>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
|
||||
|
||||
namespace fc {
|
||||
|
|
@ -30,15 +32,37 @@ namespace fc {
|
|||
}
|
||||
file_appender::~file_appender(){}
|
||||
|
||||
// MS THREAD METHOD MESSAGE \t\t\t File:Line
|
||||
void file_appender::log( const log_message& m )
|
||||
{
|
||||
fc::string message = fc::format_string( m.get_format(), m.get_data() );
|
||||
fc::variant lmsg(m);
|
||||
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() <<" ";
|
||||
|
||||
fc::string fmt_str = fc::format_string( my->cfg.format, mutable_variant_object(lmsg.get_object())( "message", message) );
|
||||
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::variant lmsg(m);
|
||||
|
||||
// fc::string fmt_str = fc::format_string( my->cfg.format, mutable_variant_object(m.get_context())( "message", message) );
|
||||
{
|
||||
fc::scoped_lock<boost::mutex> lock(my->slock);
|
||||
my->out << fmt_str << "\n";
|
||||
my->out << line.str() << "\t\t\t" << m.get_context().get_file() <<":"<<m.get_context().get_line_number()<<"\n";
|
||||
}
|
||||
if( my->cfg.flush ) my->out.flush();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue