test-vs-LOG-static.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: static!
5 
6 #include <easylogging++.h>
7 // Catch also defines CHECK(), and so we have to undefine it or we get compilation errors!
8 #undef CHECK
9 #define CATCH_CONFIG_MAIN
10 #include "../catch.h"
11 
12 // With Catch2, turn this into SCOPED_INFO (right now, does not work)
13 #if 1
14 #define TRACE(X) do { \
15  std::cout << X; \
16  } while(0)
17 #else
18 #define TRACE(X) do {} while(0)
19 #endif
20 
21 #include "../src/log.h"
22 
23 
24 using namespace librealsense;
25 
26 
27 TEST_CASE( "rs2_log vs LOG() - internal", "[log]" )
28 {
29  size_t n_callbacks = 0;
31  {
32  public:
33  size_t* pn_callbacks = nullptr; // only the default ctor is available to us...!
34  protected:
35  void handle( const el::LogDispatchData* data ) noexcept override
36  {
37  (*pn_callbacks)++;
38  TRACE( data->logMessage()->logger()->logBuilder()->build( data->logMessage(), true ));
39  }
40  };
41  el::Helpers::installLogDispatchCallback< default_dispatcher >( "default_dispatcher" );
42  auto dispatcher = el::Helpers::logDispatchCallback< default_dispatcher >( "default_dispatcher" );
43  dispatcher->pn_callbacks = &n_callbacks;
44  // Make sure the default logger dispatch (which will log to standard out/err) is disabled
46 
47  // LOG(XXX) should log to the default logger, which is NOT the librealsense logger
48  LOG(INFO) << "Log message to default logger";
49  REQUIRE( n_callbacks == 1 );
50 
51  // CLOG(XXX,"librealsense") is the librealsense logger
52  CLOG(INFO, "librealsense") << "Log message to \"librealsense\" logger";
53  REQUIRE( n_callbacks == 2 );
54 
55  // LOG_XXX() is same as CLOG( ..., "librealsense" )
56  LOG_INFO( "Log message using LOG_INFO()" );
57  REQUIRE( n_callbacks == 3 );
58 
59  // LOG_XXX() is same as CLOG( ..., "librealsense" )
60  REQUIRE_NOTHROW( rs2_log( RS2_LOG_SEVERITY_INFO, "Log message using rs2_log()", nullptr ));
61  REQUIRE( n_callbacks == 4 );
62 
63  // NOTE that all the above called the same callback!! Callbacks are not logger-specific!
64 }
dispatcher pn_callbacks
#define TEST_CASE(...)
Definition: catch.hpp:17434
void handle(const el::LogDispatchData *data) noexceptoverride
LOG(INFO)<< "Log message to default logger"
void rs2_log(rs2_log_severity severity, const char *message, rs2_error **error)
Definition: rs.cpp:2600
CLOG(INFO,"librealsense")<< "Log message to \"librealsense\" logger"
REQUIRE(n_callbacks==1)
#define TRACE(X)
auto dispatcher
LOG_INFO("Log message using LOG_INFO()")
REQUIRE_NOTHROW(rs2_log(RS2_LOG_SEVERITY_INFO,"Log message using rs2_log()", nullptr))
#define INFO(msg)
Definition: catch.hpp:17429
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