Update boost log init parameters.

This commit is contained in:
luocai 2023-12-25 18:52:51 +08:00
parent a2d1d4464f
commit a7442cb0ca
7 changed files with 57 additions and 9 deletions

17
.vscode/c_cpp_properties.json vendored Normal file
View File

@ -0,0 +1,17 @@
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/opt/Libraries/boost_1_84_0/include"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c17",
"cppStandard": "gnu++17",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4
}

View File

@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 3.15)
project(Kylin) project(Kylin)
option(UNIT_TEST "do unit test" OFF)
set(OpenSSL_LIBRARY ssl crypto) set(OpenSSL_LIBRARY ssl crypto)
@ -20,3 +22,7 @@ endif()
if(TARGET Boost::log) if(TARGET Boost::log)
add_subdirectory(Universal) add_subdirectory(Universal)
endif() endif()
if(UNIT_TEST)
add_subdirectory(UnitTest)
endif()

16
UnitTest/CMakeLists.txt Normal file
View File

@ -0,0 +1,16 @@
find_package(Boost REQUIRED COMPONENTS unit_test_framework)
# --detect_memory_leak=0 --run_test=MarkdownParserTest,ProcessUtilityTest
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_executable(UnitTest main.cpp
)
target_compile_definitions(UnitTest
PUBLIC LOG_FILTER_LEVEL=1
)
target_link_libraries(UnitTest
PRIVATE Boost::unit_test_framework
)

2
UnitTest/main.cpp Normal file
View File

@ -0,0 +1,2 @@
#define BOOST_TEST_MODULE KylinLibraryTest
#include "boost/test/included/unit_test.hpp"

View File

@ -17,7 +17,7 @@ BOOST_LOG_GLOBAL_LOGGER_INIT(location_logger, LocationLogger<boost::log::trivial
return lg; return lg;
} }
void initBoostLog(const std::string &name, boost::log::trivial::severity_level filter) { void initBoostLog(const std::string &filename, const std::string &target, boost::log::trivial::severity_level filter) {
static bool initialized = false; static bool initialized = false;
using namespace boost::log; using namespace boost::log;
if (!initialized) { if (!initialized) {
@ -30,9 +30,9 @@ void initBoostLog(const std::string &name, boost::log::trivial::severity_level f
boost::log::core::get()->add_sink(sink); boost::log::core::get()->add_sink(sink);
#else #else
std::ostringstream oss; std::ostringstream oss;
oss << name << "_%Y-%m-%d_%H.%M.%S_%N.log"; oss << filename << "_%Y-%m-%d_%H.%M.%S_%N.log";
auto fileSink = auto fileSink =
add_file_log(keywords::file_name = oss.str(), keywords::auto_flush = true, keywords::target = "logs"); add_file_log(keywords::file_name = oss.str(), keywords::auto_flush = true, keywords::target = target);
fileSink->set_formatter(&logFormatter); fileSink->set_formatter(&logFormatter);
#endif #endif
initialized = true; initialized = true;

View File

@ -52,8 +52,15 @@
#define LOG_FILTER_LEVEL (boost::log::trivial::info) #define LOG_FILTER_LEVEL (boost::log::trivial::info)
#endif #endif
/**
* @brief
*
* @param filename log file path
* @param target path for rotated log files
* @param filter
*/
void initBoostLog( void initBoostLog(
const std::string &name = "app", const std::string &filename = "logs/app", const std::string &target = "logs",
boost::log::trivial::severity_level filter = static_cast<boost::log::trivial::severity_level>(LOG_FILTER_LEVEL)); boost::log::trivial::severity_level filter = static_cast<boost::log::trivial::severity_level>(LOG_FILTER_LEVEL));
namespace AmassKeywords { namespace AmassKeywords {

View File

@ -1,6 +1,7 @@
#!/bin/bash #!/bin/bash
base_path=$(pwd) base_path=$(pwd)
qt_prefix_path="/opt/Qt/6.6.1/gcc_64"
libraries_root="/opt/Libraries" libraries_root="/opt/Libraries"
if [ $base_path == /home/* ] || [ -n "${DRONE}" ]; then if [ $base_path == /home/* ] || [ -n "${DRONE}" ]; then
build_path=${base_path}/build build_path=${base_path}/build
@ -9,8 +10,7 @@ else
fi fi
echo "build directory: $build_path" echo "build directory: $build_path"
if [ -d "/opt/Qt/6.5.2/gcc_64" ]; then if [ -d ${qt_prefix_path} ]; then # 先找Qt6
qt_prefix_path="/opt/Qt/6.5.2/gcc_64"
cmake_qt_parameters="-DCMAKE_PREFIX_PATH=${qt_prefix_path} \ cmake_qt_parameters="-DCMAKE_PREFIX_PATH=${qt_prefix_path} \
-DQT_QMAKE_EXECUTABLE=${qt_prefix_path}/bin/qmake \ -DQT_QMAKE_EXECUTABLE=${qt_prefix_path}/bin/qmake \
-DQT_DIR=${qt_prefix_path}/lib/cmake/Qt6 \ -DQT_DIR=${qt_prefix_path}/lib/cmake/Qt6 \
@ -35,7 +35,7 @@ elif [ -d "/opt/Qt/5.15.2/gcc_64" ]; then
-DQt5Svg_DIR=${qt_prefix_path}/lib/cmake/Qt5Svg " -DQt5Svg_DIR=${qt_prefix_path}/lib/cmake/Qt5Svg "
else else
cmake_qt_parameters="" cmake_qt_parameters=""
echo "please install qt6.5.2 or qt5.15.2 ..." echo "please install qt6.6.1 or qt5.15.2 ..."
fi fi
function cmake_scan() { function cmake_scan() {
@ -47,7 +47,7 @@ function cmake_scan() {
-S ${base_path} \ -S ${base_path} \
-B ${build_path} \ -B ${build_path} \
-DCMAKE_BUILD_TYPE=Debug \ -DCMAKE_BUILD_TYPE=Debug \
-DBOOST_ROOT=${libraries_root}/boost_1_83_0 \ -DBOOST_ROOT=${libraries_root}/boost_1_84_0 \
-DZeroMQ_ROOT=${libraries_root}/zeromq-4.3.4_debug \ -DZeroMQ_ROOT=${libraries_root}/zeromq-4.3.4_debug \
${cmake_qt_parameters} ${cmake_qt_parameters}
} }