Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement/1755 Improve Logging 2 #2095

Open
wants to merge 20 commits into
base: v4.0.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<img src="https://uploads-ssl.webflow.com/5be05ae542686c4ebf192462/5be2f8beb08f6d0fbd2ea797_Skale_Logo_Blue-p-500.png"><br><br>
</div>

---------------
-----------------


# SKALED – SKALE C++ Client
Expand Down
4 changes: 2 additions & 2 deletions libbatched-io/batched_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ std::string test_crash_at;
namespace batched_io {
void test_crash_before_commit( const std::string& id ) {
if ( !test_crash_at.empty() ) {
cnote << "test_crash_before_commit: " << id << std::endl;
cnote << "test_crash_before_commit: " << id;
if ( id == test_crash_at ) {
cerror << "test_crash_before_commit: crashing at " << test_crash_at << std::endl;
cerror << "test_crash_before_commit: crashing at " << test_crash_at;
_exit( 33 );
}
} // if 1
Expand Down
36 changes: 19 additions & 17 deletions libdevcore/BMPBN_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,27 +50,27 @@ inline bool test1( const std::string& s, bool bIsVerbose ) {
ss << std::hex << std::setw( 2 ) << std::setfill( '0' ) << int( buffer[0] );
if ( bIsVerbose ) {
while ( --length > 0 )
ss << cc::debug( ":" ) << std::setw( 2 ) << std::setfill( '0' )
<< int( buffer[++index] );
ss << ":" << std::setw( 2 ) << std::setfill( '0' ) << int( buffer[++index] );
}
if ( bIsVerbose )
ss << cc::debug( " = " ) << std::dec << std::setw( 1 ) << x << cc::debug( ", " );
ss << " = " << std::dec << std::setw( 1 ) << x << ", ";
if ( x != y ) {
if ( bIsVerbose )
std::cout << " " << ss.str() << cc::fatal( "FAILED" ) << "\n";
std::cout << " " << ss.str() << "FAILED"
<< "\n";
return false;
}
// if ( bIsVerbose )
// std::cout << " " << cc::success( "OK for " ) << cc::info( s ) << "\n";
// std::cout << " " << "OK for " ) << s ) << "\n";
return true;
} // namespace rpc

template < class T >
inline bool test(
bool bIncludeNegative, bool bIncludeHuge, bool bIsVerbose, const char* strTypeDescription ) {
if ( bIsVerbose && strTypeDescription && strTypeDescription[0] )
std::cout << cc::debug( "Testing conversion of " ) << cc::info( strTypeDescription )
<< cc::debug( "..." ) << "\n";
std::cout << "Testing conversion of " << strTypeDescription << "..."
<< "\n";
bool bOKay = true;
//
if ( !test1< T >( std::string( "0" ), bIsVerbose ) )
Expand Down Expand Up @@ -159,11 +159,12 @@ inline bool test(
}
if ( bIsVerbose && strTypeDescription && strTypeDescription[0] ) {
if ( bOKay )
std::cout << cc::success( "Successful conversion test of " )
<< cc::info( strTypeDescription ) << cc::success( "." ) << "\n";
std::cout << "Successful conversion test of " << strTypeDescription << "."
<< "\n";
else
std::cout << cc::fatal( "FAILED" ) << cc::error( " conversion test of " )
<< cc::warn( strTypeDescription ) << cc::error( "." ) << "\n";
std::cout << "FAILED"
<< " conversion test of " << strTypeDescription << "."
<< "\n";
}
return bOKay;
} // namespace BMPBN
Expand All @@ -172,8 +173,8 @@ template < class T >
inline bool test_limit_limbs_and_halves(
const char* strStartValue, size_t nBits, bool bIsVerbose ) {
if ( bIsVerbose )
std::cout << cc::debug( "Testing limit margin of " ) << cc::size10( nBits )
<< cc::debug( " bit values..." ) << "\n";
std::cout << "Testing limit margin of " << nBits << " bit values..."
<< "\n";
bool bOKay = true;
if ( !test1< T >( std::string( strStartValue ), bIsVerbose ) )
bOKay = false;
Expand All @@ -187,11 +188,12 @@ inline bool test_limit_limbs_and_halves(
}
if ( bIsVerbose ) {
if ( bOKay )
std::cout << cc::success( "Successful conversion test of " ) << cc::size10( nBits )
<< cc::success( " bit values." ) << "\n";
std::cout << "Successful conversion test of " << nBits << " bit values."
<< "\n";
else
std::cout << cc::fatal( "FAILED" ) << cc::error( " conversion test of " )
<< cc::size10( nBits ) << cc::debug( " bit values" ) << "\n";
std::cout << "FAILED"
<< " conversion test of " << nBits << " bit values"
<< "\n";
}
return bOKay;
}
Expand Down
31 changes: 14 additions & 17 deletions libdevcore/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void ExitHandler::exitHandler( int nSignalNo, ExitHandler::exit_code_t ec ) {
string( "\nInternal exit requested while already exiting. " ) :
"\nInternal exit initiated. ";
}
std::cerr << strMessagePrefix << skutils::signal::signal2str( nSignalNo ) << "\n\n";
cerror << strMessagePrefix << skutils::signal::signal2str( nSignalNo ) << "\n\n";

switch ( nSignalNo ) {
case SIGINT:
Expand All @@ -85,10 +85,10 @@ void ExitHandler::exitHandler( int nSignalNo, ExitHandler::exit_code_t ec ) {
case SIGFPE:
case SIGSEGV:
// abort signals
std::cout << "\n" << skutils::signal::generate_stack_trace() << "\n";
std::cout.flush();
std::cout << skutils::signal::read_maps() << "\n";
std::cout.flush();
cerror << "\n" << skutils::signal::generate_stack_trace();
cerror.flush();
cerror << skutils::signal::read_maps();
cerror.flush();

_exit( nSignalNo + 128 );

Expand All @@ -106,10 +106,9 @@ void ExitHandler::exitHandler( int nSignalNo, ExitHandler::exit_code_t ec ) {
auto start_time = std::chrono::steady_clock::now();

std::thread( [nSignalNo, start_time]() {
std::cerr << ( "\n" + string( "SELF-KILL:" ) + " " + "Will sleep " +
cc::size10( ExitHandler::KILL_TIMEOUT ) +
" seconds before force exit..." ) +
"\n\n";
cerror << "\nSELF-KILL: "
<< "Will sleep " << ExitHandler::KILL_TIMEOUT
<< " seconds before force exit...";

clog( VerbosityInfo, "exit" ) << "THREADS timer started";

Expand All @@ -125,10 +124,9 @@ void ExitHandler::exitHandler( int nSignalNo, ExitHandler::exit_code_t ec ) {
threads = new_threads;

if ( threads_diff.size() ) {
cerr << seconds << " THREADS " << threads.size() << ":";
cerror << seconds << " THREADS " << threads.size() << ":";
for ( const string& t : threads_diff )
cerr << " " << t;
cerr << endl;
cerror << " " << t;
}
} catch ( ... ) {
// swallow it
Expand All @@ -137,10 +135,9 @@ void ExitHandler::exitHandler( int nSignalNo, ExitHandler::exit_code_t ec ) {
std::this_thread::sleep_for( 100ms );
}

std::cerr << ( "\n" + string( "SELF-KILL:" ) + " " +
"Will force exit after sleeping " +
cc::size10( ExitHandler::KILL_TIMEOUT ) + cc::error( " second(s)" ) +
"\n\n" );
cerror << "\nSELF-KILL: "
<< "Will force exit after sleeping " << ExitHandler::KILL_TIMEOUT
<< " second(s)";

// TODO deduplicate this with main() before return
ExitHandler::exit_code_t ec = ExitHandler::requestedExitCode();
Expand All @@ -158,7 +155,7 @@ void ExitHandler::exitHandler( int nSignalNo, ExitHandler::exit_code_t ec ) {

// TODO deduplicate with first if()
if ( ExitHandler::shouldExit() && s_nStopSignal > 0 && nSignalNo > 0 ) {
std::cerr << ( "\n" + string( "SIGNAL-HANDLER:" ) + " " + "Will force exit now...\n\n" );
cerror << "\nSIGNAL-HANDLER: Will force exit now...";
_exit( 13 );
}

Expand Down
2 changes: 0 additions & 2 deletions libdevcore/Exceptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ std::string innermost_exception_what( const std::exception& ex ) {
}

void rethrow_most_nested( const std::exception& ex ) {
// std::cerr << nested_exception_what(ex) << std::endl;

const std::nested_exception* nested_ptr = dynamic_cast< const std::nested_exception* >( &ex );
if ( nested_ptr == nullptr ) {
throw; // TODO can we make this func to be called without arguments? what does it really
Expand Down
10 changes: 4 additions & 6 deletions libdevcore/Log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,10 @@ void setupLogging( LoggingOptions const& _options ) {
ss << channel;
strChannel = ss.str();
} // block
sink->set_formatter( expr::stream
<< timestamp << " " << cc::info( strThreadName ) << " "
<< cc::warn( strChannel )
<< expr::if_( expr::has_attr(
context ) )[expr::stream << " " << cc::warn( strChannel )]
<< " " << expr::smessage );
sink->set_formatter(
expr::stream << timestamp << " " << strThreadName << " " << strChannel
<< expr::if_( expr::has_attr( context ) )[expr::stream << " " << strChannel]
<< " " << expr::smessage );

boost::log::core::get()->add_sink( sink );
boost::log::core::get()->add_global_attribute(
Expand Down
Loading
Loading