Skip to content

Commit

Permalink
Merge pull request IntelRealSense#922 from friissoren/make_logging_op…
Browse files Browse the repository at this point in the history
…tional

Allow removal of EasyLogging++ from the build
  • Loading branch information
dorodnic authored Dec 20, 2017
2 parents d2810f8 + 0f86c70 commit 90fc463
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
13 changes: 11 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ if(BUILD_WITH_OPENMP)
endif()
endif()

option(BUILD_EASYLOGGINGPP "Build EasyLogging++ as a part of the build" ON)

if (BUILD_EASYLOGGINGPP)
add_definitions(-DBUILD_EASYLOGGINGPP)
endif()

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/CMake)

set(REALSENSE_CPP
Expand Down Expand Up @@ -118,7 +124,6 @@ set(REALSENSE_CPP
src/ds5/advanced_mode/presets.cpp
src/ds5/advanced_mode/advanced_mode.cpp

third-party/easyloggingpp/src/easylogging++.cc
third-party/sqlite/sqlite3.c

src/mock/sql.cpp
Expand Down Expand Up @@ -234,14 +239,18 @@ set(REALSENSE_HPP
src/ds5/advanced_mode/json_loader.hpp
src/ds5/advanced_mode/presets.h

third-party/easyloggingpp/src/easylogging++.h
third-party/sqlite/sqlite3.h
src/mock/sql.h
src/mock/recorder.h

src/media/ros/ros_file_format.h
)

if(BUILD_EASYLOGGINGPP)
list(APPEND REALSENSE_CPP third-party/easyloggingpp/src/easylogging++.cc)
list(APPEND REALSENSE_HPP third-party/easyloggingpp/src/easylogging++.h)
endif()

if(WIN32)
source_group("Source Files\\Backend" FILES
src/win/win-helpers.cpp
Expand Down
15 changes: 14 additions & 1 deletion src/log.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "types.h"

#include <fstream>
#include <iostream>

#if BUILD_EASYLOGGINGPP
INITIALIZE_EASYLOGGINGPP

namespace librealsense
Expand Down Expand Up @@ -147,3 +147,16 @@ void librealsense::log_to_file(rs2_log_severity min_severity, const char * file_
{
logger.log_to_file(min_severity, file_path);
}

#else // BUILD_EASYLOGGINGPP

void librealsense::log_to_console(rs2_log_severity min_severity)
{
}

void librealsense::log_to_file(rs2_log_severity min_severity, const char * file_path)
{
}

#endif // BUILD_EASYLOGGINGPP

14 changes: 14 additions & 0 deletions src/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <sstream> // For ostringstream
#include <mutex> // For mutex, unique_lock
#include <memory> // For unique_ptr
#include <iostream>
#include <map>
#include <limits>
#include <algorithm>
Expand All @@ -27,7 +28,9 @@

#include "concurrency.h"

#if BUILD_EASYLOGGINGPP
#include "../third-party/easyloggingpp/src/easylogging++.h"
#endif // BUILD_EASYLOGGINGPP

typedef unsigned char byte;

Expand Down Expand Up @@ -64,12 +67,23 @@ namespace librealsense
void log_to_console(rs2_log_severity min_severity);
void log_to_file(rs2_log_severity min_severity, const char * file_path);

#if BUILD_EASYLOGGINGPP

#define LOG_DEBUG(...) do { CLOG(DEBUG ,"librealsense") << __VA_ARGS__; } while(false)
#define LOG_INFO(...) do { CLOG(INFO ,"librealsense") << __VA_ARGS__; } while(false)
#define LOG_WARNING(...) do { CLOG(WARNING ,"librealsense") << __VA_ARGS__; } while(false)
#define LOG_ERROR(...) do { CLOG(ERROR ,"librealsense") << __VA_ARGS__; } while(false)
#define LOG_FATAL(...) do { CLOG(FATAL ,"librealsense") << __VA_ARGS__; } while(false)

#else // BUILD_EASYLOGGINGPP

#define LOG_DEBUG(...) do { ; } while(false)
#define LOG_INFO(...) do { ; } while(false)
#define LOG_WARNING(...) do { ; } while(false)
#define LOG_ERROR(...) do { ; } while(false)
#define LOG_FATAL(...) do { ; } while(false)

#endif // BUILD_EASYLOGGINGPP

//////////////////////////
// Exceptions mechanism //
Expand Down

0 comments on commit 90fc463

Please sign in to comment.