Skip to content

Commit

Permalink
ac_logger can now be disabled/enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
maloel committed May 12, 2020
1 parent d297c43 commit b2845c6
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions unit-tests/algo/depth-to-rgb-calibration/ac-logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@
// screen
class ac_logger
{
class dispatch : public el::LogDispatchCallback
struct dispatch : public el::LogDispatchCallback
{
protected:
bool * _p_on;

void handle( const el::LogDispatchData* data ) noexcept override
{
if( !*_p_on )
return;
char const * raw = data->logMessage()->message().data();
if( !strncmp( AC_LOG_PREFIX, raw, AC_LOG_PREFIX_LEN ) )
{
Expand All @@ -31,13 +34,21 @@ class ac_logger
}
}
};

bool _on;

public:
explicit ac_logger()
explicit ac_logger( bool on = true )
: _on( on )
{
el::Loggers::getLogger( "librealsense" );

el::Helpers::installLogDispatchCallback< dispatch >( "our_dispatch" );
auto dispatcher = el::Helpers::logDispatchCallback< dispatch >( "our_dispatch" );
dispatcher->_p_on = &_on;
el::Helpers::uninstallLogDispatchCallback< el::base::DefaultLogDispatchCallback >( "DefaultLogDispatchCallback" );
}

void enable( bool on = true ) { _on = on; }

};

0 comments on commit b2845c6

Please sign in to comment.