diff options
author | Yatian XU <yatian.xu@nokia-sbell.com> | 2019-09-10 13:47:16 +0800 |
---|---|---|
committer | Yatian XU <yatian.xu@nokia-sbell.com> | 2019-09-10 13:47:16 +0800 |
commit | 6c27d22ac7af3d1379a5448eef5894083bcae9ec (patch) | |
tree | d5b10cb237d3bb0b1dc172beb42c8ef6f31fc67f | |
parent | 9454af15a87774a642b20f34ecc21a1bd84779c4 (diff) |
Contribute C++ implement of VES spec 7.0.1 to ONAP/vnfsdk:
Part2: Makefile, Logging
Issue-ID: VNFSDK-466
Signed-off-by: Yatian XU <yatian.xu@nokia-sbell.com>
Change-Id: I7215dd01a7189fe4d7a57b05bed2ebc05889ce61
10 files changed, 133 insertions, 0 deletions
diff --git a/veslibrary/ves_cpplibrary/src/CMakeLists.txt b/veslibrary/ves_cpplibrary/src/CMakeLists.txt new file mode 100755 index 0000000..b788dab --- /dev/null +++ b/veslibrary/ves_cpplibrary/src/CMakeLists.txt @@ -0,0 +1,15 @@ +cmake_minimum_required (VERSION 2.8) + +project (xvesagent) + +set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "${CMAKE_SOURCE_DIR}/cmake/") + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") + +OPTION (ENABLE_COVERAGE "Use gcov" OFF) +MESSAGE(STATUS ENABLE_COVERAGE=${ENABLE_COVERAGE}) +IF(ENABLE_COVERAGE) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage") +ENDIF() + +add_subdirectory(lib) diff --git a/veslibrary/ves_cpplibrary/src/Makefile b/veslibrary/ves_cpplibrary/src/Makefile new file mode 100644 index 0000000..b0bc5eb --- /dev/null +++ b/veslibrary/ves_cpplibrary/src/Makefile @@ -0,0 +1,20 @@ +all: + mkdir build + cd build; cmake ..; make; make install + +.PHONY : test +test: + mkdir build + cd build; cmake .. -DENABLE_COVERAGE=ON; make; make install + mkdir test/build + cd test/build; cmake .. -DENABLE_COVERAGE=ON; make; ./xtest + lcov -c -d build/lib/encode/CMakeFiles/xencode.dir -d build/lib/transport/CMakeFiles/xtransport.dir -o coverage.info + lcov -r coverage.info '/usr/*' '*/transport/gen-cpp/*' -o xvesagent.info + genhtml xvesagent.info -o coverage + rm -rf *.info + +clean: + rm *.info -rf + rm build -rf + rm coverage -rf + rm test/build -rf diff --git a/veslibrary/ves_cpplibrary/src/cmake/leveldbConfig.cmake b/veslibrary/ves_cpplibrary/src/cmake/leveldbConfig.cmake new file mode 100644 index 0000000..63bae3c --- /dev/null +++ b/veslibrary/ves_cpplibrary/src/cmake/leveldbConfig.cmake @@ -0,0 +1,5 @@ +find_library(LEVELDB_LIBRARY libleveldb.a) +find_path(LEVELDB_INCLUDE_DIR leveldb/db.h) +message("leveldb include dir: ${LEVELDB_INCLUDE_DIR}") +message("leveldb library dir: ${LEVELDB_LIBRARY}") + diff --git a/veslibrary/ves_cpplibrary/src/cmake/thriftConfig.cmake b/veslibrary/ves_cpplibrary/src/cmake/thriftConfig.cmake new file mode 100644 index 0000000..0c0bb5f --- /dev/null +++ b/veslibrary/ves_cpplibrary/src/cmake/thriftConfig.cmake @@ -0,0 +1,5 @@ +find_library(THRIFT_LIBRARY libthrift.a) +find_path(THRIFT_INCLUDE_DIR thrift/Thrift.h) +message("thrift include dir: ${THRIFT_INCLUDE_DIR}") +message("thrift library dir: ${THRIFT_LIBRARY}") + diff --git a/veslibrary/ves_cpplibrary/src/cmake/xencodeConfig.cmake b/veslibrary/ves_cpplibrary/src/cmake/xencodeConfig.cmake new file mode 100644 index 0000000..2c8c993 --- /dev/null +++ b/veslibrary/ves_cpplibrary/src/cmake/xencodeConfig.cmake @@ -0,0 +1,6 @@ +find_library(XENCODE_LIBRARY xencode) +find_path(XENCODE_INCLUDE_DIR xvesagent/xencode/XEvent.h) +set(XENCODE_INCLUDE_DIR "${XENCODE_INCLUDE_DIR}/xvesagent/xencode") +message("xencode include dir: ${XENCODE_INCLUDE_DIR}") +message("xencode library dir: ${XENCODE_LIBRARY}") + diff --git a/veslibrary/ves_cpplibrary/src/cmake/xlogConfig.cmake b/veslibrary/ves_cpplibrary/src/cmake/xlogConfig.cmake new file mode 100644 index 0000000..819279f --- /dev/null +++ b/veslibrary/ves_cpplibrary/src/cmake/xlogConfig.cmake @@ -0,0 +1,4 @@ +find_path(XLOG_INCLUDE_DIR xvesagent/XLog.h) +set(XLOG_INCLUDE_DIR "${XLOG_INCLUDE_DIR}/xvesagent") +message("xlog include dir: ${XLOG_INCLUDE_DIR}") + diff --git a/veslibrary/ves_cpplibrary/src/cmake/xtransportConfig.cmake b/veslibrary/ves_cpplibrary/src/cmake/xtransportConfig.cmake new file mode 100644 index 0000000..f0163eb --- /dev/null +++ b/veslibrary/ves_cpplibrary/src/cmake/xtransportConfig.cmake @@ -0,0 +1,6 @@ +find_library(XTRANSPORT_LIBRARY xtransport) +find_path(XTRANSPORT_INCLUDE_DIR xvesagent/xtransport/XTransport.h) +set(XTRANSPORT_INCLUDE_DIR "${XTRANSPORT_INCLUDE_DIR}/xvesagent/xtransport") +message("xtransport include dir: ${XTRANSPORT_INCLUDE_DIR}") +message("xtransport library dir: ${XTRANSPORT_LIBRARY}") + diff --git a/veslibrary/ves_cpplibrary/src/lib/CMakeLists.txt b/veslibrary/ves_cpplibrary/src/lib/CMakeLists.txt new file mode 100755 index 0000000..51f59d1 --- /dev/null +++ b/veslibrary/ves_cpplibrary/src/lib/CMakeLists.txt @@ -0,0 +1,12 @@ +add_subdirectory(encode) +add_subdirectory(transport) + +file(GLOB COM_HDRS "common/*.h") + +install(FILES ${COM_HDRS} + DESTINATION "include/xvesagent" +) + +install(FILES ../cmake/xlogConfig.cmake + DESTINATION "lib/cmake/xlog" +) diff --git a/veslibrary/ves_cpplibrary/src/lib/common/XLog.cpp b/veslibrary/ves_cpplibrary/src/lib/common/XLog.cpp new file mode 100755 index 0000000..ba628b9 --- /dev/null +++ b/veslibrary/ves_cpplibrary/src/lib/common/XLog.cpp @@ -0,0 +1,25 @@ +#include "XLog.h"
+#include "spdlog/spdlog.h"
+#include "spdlog/sinks/rotating_file_sink.h"
+#include "spdlog/sinks/stdout_color_sinks.h"
+
+void vagt::log::init(const std::string& path, int logFileSize, int logFileNum)
+{
+ auto logger = spdlog::rotating_logger_mt("xvagt", path, logFileSize, logFileNum);
+ spdlog::set_default_logger(logger);
+ spdlog::default_logger()->set_pattern("%^%L%$ [%Y-%m-%d %H:%M:%S.%e][%t][%@] %v");
+ spdlog::default_logger()->flush_on(spdlog::level::info);
+ spdlog::default_logger()->set_level(spdlog::level::info);
+ /*
+ spdlog::default_logger()->set_pattern("%^%L%$ [%Y-%m-%d %H:%M:%S.%e][%t][%@] %v");
+ spdlog::flush_on(spdlog::level::info);
+ spdlog::set_level(spdlog::level::info);
+ */
+}
+
+void vagt::log::setLevel(vagt::log::XLogLevel level)
+{
+ spdlog::default_logger()->set_level(spdlog::level::level_enum(level));
+ spdlog::default_logger()->flush_on(spdlog::level::level_enum(level));
+}
+
diff --git a/veslibrary/ves_cpplibrary/src/lib/common/XLog.h b/veslibrary/ves_cpplibrary/src/lib/common/XLog.h new file mode 100755 index 0000000..aae8c31 --- /dev/null +++ b/veslibrary/ves_cpplibrary/src/lib/common/XLog.h @@ -0,0 +1,35 @@ +#pragma once
+
+#include <string>
+
+namespace vagt
+{
+ namespace log
+ {
+ /*************************************************************************************************//** + * @brief Log level + *****************************************************************************************************/ + enum XLogLevel + { + XLogTrace, + XLogDebug, + XLogInfo, + XLogWarn, + XLogErr, + XLogCritical, + XLogOff, + };
+
+ /*************************************************************************************************//**
+ * Initialize the file logging.
+ *
+ * @note To disable logging, set the path to "/dev/null" .
+ *****************************************************************************************************/
+ void init(const std::string& path, int logFileSize = 1048576 * 5, int logFileNum = 10);
+
+ /*************************************************************************************************//**
+ * Set log level.
+ *****************************************************************************************************/
+ void setLevel(XLogLevel level);
+ }
+}
|