incremental
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 56f2c2a..323747a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -39,7 +39,7 @@
find_package(Boost COMPONENTS system thread regex REQUIRED)
#Openssl
-hunter_add_package(OpenSSL)
+#hunter_add_package(OpenSSL)
find_package(OpenSSL REQUIRED)
if (NOT OPENSSL_FOUND)
message(FATAL_ERROR "Could not find OpenSSL")
@@ -50,19 +50,31 @@
include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/crow/include)
#g3 logging
-set(ADD_FATAL_EXAMPLE OFF)
+option(ADD_FATAL_EXAMPLE "Disable g3 examples" OFF)
add_subdirectory(g3log)
include_directories(g3log/src)
# Debug sanitizers
find_package(Sanitizers)
+
+set(SRC_FILES
+ src/example.cpp
+ include/crow_g3_logger.hpp
+ include/ssl_key_handler.hpp
+ include/color_cout_g3_sink.hpp
+)
+
# Executable
-add_executable(example ${CMAKE_CURRENT_SOURCE_DIR}/src/example.cpp)
+
+add_executable(bmcweb ${SRC_FILES})
#target_link_libraries(example crow)
-target_link_libraries(example Boost::boost Boost::system)
-target_link_libraries(example ${CMAKE_THREAD_LIBS_INIT})
-target_link_libraries(example OpenSSL::SSL OpenSSL::Crypto)
-target_link_libraries(example g3logger)
+target_link_libraries(bmcweb Boost::boost Boost::system)
+target_link_libraries(bmcweb ${CMAKE_THREAD_LIBS_INIT})
+target_link_libraries(bmcweb OpenSSL::SSL OpenSSL::Crypto)
+target_link_libraries(bmcweb g3logger)
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
-
+# this needs to be at the end to make sure all includes are handled correctly
+get_property(C_INCLUDE_DIRS DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
+execute_process(COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/scripts/prime_vscode_compile_db.py ${C_INCLUDE_DIRS})
diff --git a/src/ColorCoutG3Sink.hpp b/include/color_cout_g3_sink.hpp
similarity index 100%
rename from src/ColorCoutG3Sink.hpp
rename to include/color_cout_g3_sink.hpp
diff --git a/include/crow_g3_logger.hpp b/include/crow_g3_logger.hpp
new file mode 100644
index 0000000..e39269a
--- /dev/null
+++ b/include/crow_g3_logger.hpp
@@ -0,0 +1,92 @@
+#pragma once
+
+// This file overrides the default crow logging framework to use g3 instead.
+// It implements enough of the interfaces of the crow logging framework to work correctly
+// but deletes the ILogHandler interface, as usage of that would be counter to the g3
+// handler management, and would cause performance issues.
+
+
+#include <string>
+#include <cstdio>
+#include <cstdlib>
+#include <ctime>
+#include <iostream>
+#include <sstream>
+
+#include <g3log/g3log.hpp>
+#include <g3log/logworker.hpp>
+
+namespace crow
+{
+ enum class LogLevel
+ {
+#ifndef ERROR
+ DEBUG = 0,
+ INFO,
+ WARNING,
+ ERROR,
+ CRITICAL,
+#endif
+
+ Debug = 0,
+ Info,
+ Warning,
+ Error,
+ Critical,
+ };
+
+ class logger {
+
+ public:
+
+
+ logger(std::string prefix, LogLevel level) : level_(level) {
+ // no op, let g3 handle th log levels
+
+ }
+
+ //
+ template <typename T>
+ logger& operator<<(T const &value) {
+
+ #ifdef CROW_ENABLE_LOGGING
+ if(level_ >= get_current_log_level()) {
+ stringstream_ << value;
+ }
+ #endif
+ return *this;
+ }
+
+ //
+ static void setLogLevel(LogLevel level) {
+ get_log_level_ref() = level;
+ }
+
+ static LogLevel get_current_log_level() {
+ return get_log_level_ref();
+ }
+
+ private:
+ //
+ static LogLevel& get_log_level_ref()
+ {
+ static LogLevel current_level = (LogLevel)CROW_LOG_LEVEL;
+ return current_level;
+ }
+
+ //
+ std::ostringstream stringstream_;
+ LogLevel level_;
+ };
+}
+
+#define CROW_LOG_CRITICAL \
+ LOG(FATAL)
+#define CROW_LOG_ERROR \
+ LOG(WARNING)
+#define CROW_LOG_WARNING \
+ LOG(WARNING)
+#define CROW_LOG_INFO \
+ LOG(INFO)
+#define CROW_LOG_DEBUG \
+ LOG(DEBUG)
diff --git a/src/ssl_key_handler.hpp b/include/ssl_key_handler.hpp
similarity index 100%
rename from src/ssl_key_handler.hpp
rename to include/ssl_key_handler.hpp
diff --git a/scripts/prime_vscode_compile_db.py b/scripts/prime_vscode_compile_db.py
old mode 100644
new mode 100755
index 02ae98c..82ce977
--- a/scripts/prime_vscode_compile_db.py
+++ b/scripts/prime_vscode_compile_db.py
@@ -1,10 +1,11 @@
+#! /usr/bin/python3
+
import json
import shlex
import os
import sys
SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
-
VS_CODE_FILE = os.path.join(SCRIPT_DIR, "../.vscode/c_cpp_properties.json")
def main():
diff --git a/src/example.cpp b/src/example.cpp
index c75ad61..91fdb7f 100644
--- a/src/example.cpp
+++ b/src/example.cpp
@@ -21,7 +21,7 @@
#include "crow/http_server.h"
#include "crow/app.h"
-#include "ColorCoutG3Sink.hpp"
+#include "color_cout_g3_sink.hpp"
#include "ssl_key_handler.hpp"
#include <iostream>