test-vs-LOG-shared.cpp
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2020 Intel Corporation. All Rights Reserved.
3 
4 //#cmake: shared!
5 
6 //#cmake: add-file log-common.h
7 #include "log-common.h"
8 
9 // Our EL++ instance is different than the rs2 one. Any LOG() calls will therefore
10 // use a different mechanism/callback than LRS's -- i.e., callbacks passed to LRS
11 // will not catach LOG() calls, and LRS won't catch our own calls either!
12 
14 {
15  // Capture any of the local (our) EL++ LOG() calls
17  {
18  public:
19  size_t* pn_callbacks = nullptr; // only the default ctor is available to us...!
20  protected:
21  void handle( const el::LogDispatchData* data ) noexcept override
22  {
23  (*pn_callbacks)++;
24  TRACE( "OUR: " << data->logMessage()->logger()->logBuilder()->build( data->logMessage(), true ) );
25  }
26  };
27 
28 protected:
29  size_t n_callbacks_lrs = 0;
30  size_t n_callbacks_our = 0;
31 
32 public:
34  {
35  // Install two callbacks: one local ...
36  el::Helpers::installLogDispatchCallback< our_dispatcher >( "our_dispatcher" );
37  auto dispatcher = el::Helpers::logDispatchCallback< our_dispatcher >( "our_dispatcher" );
38  dispatcher->pn_callbacks = &n_callbacks_our;
39  // Make sure the default logger dispatch (which will log to standard out/err) is disabled
41 
42  // ... and one inside LRS
43  auto callback = [&]( rs2_log_severity severity, rs2::log_message const& msg )
44  {
46  TRACE( "LRS: " << severity << ' ' << msg.filename() << '+' << msg.line_number() << ": " << msg.raw() );
47  };
49  }
50 
51  void reset()
52  {
53  n_callbacks_lrs = n_callbacks_our = 0;
54  }
55 };
56 
57 
58 TEST_CASE_METHOD( test_fixture, "rs2::log vs LOG()", "[log]" ) {
59 
60  reset();
61 
62  SECTION( "lrs should get its own callbacks" ) {
63  log_all();
64  REQUIRE( n_callbacks_lrs == 4 );
65  REQUIRE( n_callbacks_our == 0 );
66  }
67  SECTION( "default log; no callbacks" ) {
68  LOG(INFO) << "LOG() message to our logger";
69  REQUIRE( n_callbacks_lrs == 0 );
70  REQUIRE( n_callbacks_our == 1 );
71  }
72  SECTION( "our logger is separate from librealsense logger" ) {
73  // ("librealsense" is the name of the LRS logger; look in log.cpp)
74  CLOG( INFO, "librealsense" ) << "LOG() message to \"librealsense\" logger";
75  REQUIRE( n_callbacks_lrs == 0 );
76  REQUIRE( n_callbacks_our == 1 );
77  }
78 }
GLenum GLuint GLenum severity
void log_to_callback(rs2_log_severity min_severity, S callback)
Definition: rs.hpp:139
TEST_CASE_METHOD(test_fixture,"rs2::log vs LOG()","[log]")
LOG(INFO)<< "Log message to default logger"
CLOG(INFO,"librealsense")<< "Log message to \"librealsense\" logger"
void log_all()
Definition: log-common.h:35
void handle(const el::LogDispatchData *data) noexceptoverride
#define SECTION(...)
Definition: catch.hpp:17438
REQUIRE(n_callbacks==1)
def callback(frame)
Definition: t265_stereo.py:91
#define INFO(msg)
Definition: catch.hpp:17429
rs2_log_severity
Severity of the librealsense logger.
Definition: rs_types.h:153
el::Helpers::uninstallLogDispatchCallback< el::base::DefaultLogDispatchCallback >("DefaultLogDispatchCallback")
Definition: parser.hpp:150


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:50:11