ac-logger.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <librealsense2/h/rs_types.h> // rs2_log_severity
4 #include <string>
5 #include <iostream>
6 #include <easylogging++.h>
7 #include "../../../src/algo/depth-to-rgb-calibration/debug.h"
8 
9 
10 // This logger will catch all the realsense logs and output them to the
11 // screen
12 class ac_logger
13 {
15  {
17 
18  void handle( const el::LogDispatchData* data ) noexcept override
19  {
20  if( ! _p_logger->_on )
21  return;
22  char const * raw = data->logMessage()->message().data();
23  if( ! strncmp( AC_LOG_PREFIX, raw, AC_LOG_PREFIX_LEN ) )
24  {
25  _p_logger->on_log( *el::LevelHelper::convertToString( data->logMessage()->level() ),
26  raw + AC_LOG_PREFIX_LEN );
27  }
28  }
29  };
30 
31  bool _on;
32 
33 public:
34  explicit ac_logger( bool on = true )
35  : _on( on )
36  {
37  el::Loggers::getLogger( "librealsense" );
38 
39  el::Helpers::installLogDispatchCallback< dispatch >( "our_dispatch" );
40  auto dispatcher = el::Helpers::logDispatchCallback< dispatch >( "our_dispatch" );
41  dispatcher->_p_logger = this;
43  }
44  virtual ~ac_logger() {}
45 
46  void enable( bool on = true ) { _on = on; }
47 
48 protected:
49  virtual void on_log( char severity, char const * message )
50  {
51  std::cout << "-" << severity << "- ";
52  std::cout << message << std::endl;
53  }
54 };
GLenum GLuint GLenum GLsizei const GLchar * message
GLenum GLuint GLenum severity
ac_logger * _p_logger
Definition: ac-logger.h:16
void handle(const el::LogDispatchData *data) noexceptoverride
Definition: ac-logger.h:18
virtual ~ac_logger()
Definition: ac-logger.h:44
static const char * convertToString(Level level)
Converts level to associated const char*.
std::ostream & cout()
Exposes RealSense structs.
void enable(bool on=true)
Definition: ac-logger.h:46
static Logger * getLogger(const std::string &identity, bool registerIfNotAvailable=true)
Gets existing or registers new logger.
ac_logger(bool on=true)
Definition: ac-logger.h:34
bool _on
Definition: ac-logger.h:31
virtual void on_log(char severity, char const *message)
Definition: ac-logger.h:49
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:45:05