Compare commits
55 Commits
v1.0.10-re
...
log_rateli
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c2c9a8a704 | ||
|
|
3ecbc885fb | ||
|
|
4c9b58db56 | ||
|
|
74d3c95994 | ||
|
|
d5de7fa545 | ||
|
|
ff694442c0 | ||
|
|
174a57e01f | ||
|
|
f76af2f036 | ||
|
|
31bd3fed9c | ||
|
|
9ecf746f0f | ||
|
|
040ce55a1b | ||
|
|
cb4ad71c50 | ||
|
|
02100e4232 | ||
|
|
63f5231e9f | ||
|
|
15fe685383 | ||
|
|
e1057e6d0c | ||
|
|
2e4e4dff17 | ||
|
|
150255033c | ||
|
|
0f0e55c877 | ||
|
|
8857f282b9 | ||
|
|
cc0912eed0 | ||
|
|
186571e823 | ||
|
|
e39e641103 | ||
|
|
f461cbbc3d | ||
|
|
05a8eded4b | ||
|
|
92815d2d1f | ||
|
|
ea4185727b | ||
|
|
7066b2b086 | ||
|
|
52db3f0001 | ||
|
|
7417fed852 | ||
|
|
0cb2236be0 | ||
|
|
332201d4b0 | ||
|
|
ce403b8ca5 | ||
|
|
f15a1fd617 | ||
|
|
d42c5eeb0f | ||
|
|
49b61b11a9 | ||
|
|
bc575233b7 | ||
|
|
b4f239ae9c | ||
|
|
90fb91cd42 | ||
|
|
9c410a1e7e | ||
|
|
8dee487439 | ||
|
|
2e4c2d3098 | ||
|
|
40512a0421 | ||
|
|
ab7f4edda1 | ||
|
|
bafd63face | ||
|
|
e6e1f8494e | ||
|
|
19911a962c | ||
|
|
c21cdcb3f0 | ||
|
|
745f908d70 | ||
|
|
23609f6f02 | ||
|
|
6ae5d5ffa9 | ||
|
|
1f9fc66152 | ||
|
|
635bb180bf | ||
|
|
117720197e | ||
|
|
49822347cb |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -11,7 +11,8 @@ build/
|
|||||||
core.*
|
core.*
|
||||||
version.txt
|
version.txt
|
||||||
demo/test_handle_logger
|
demo/test_handle_logger
|
||||||
cmake-build-debug
|
cmake-build-*
|
||||||
|
build-*/
|
||||||
GPATH
|
GPATH
|
||||||
GRTAGS
|
GRTAGS
|
||||||
GTAGS
|
GTAGS
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ variables:
|
|||||||
GIT_STRATEGY: "clone"
|
GIT_STRATEGY: "clone"
|
||||||
BUILD_PADDING_PREFIX: /tmp/padding_for_CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX_PREFIX_PREFIX_PREFIX_PREFIX_PREFIX/
|
BUILD_PADDING_PREFIX: /tmp/padding_for_CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX_PREFIX_PREFIX_PREFIX_PREFIX_PREFIX/
|
||||||
INSTALL_PREFIX: "/opt/MESA/lib/"
|
INSTALL_PREFIX: "/opt/MESA/lib/"
|
||||||
|
INSTALL_DEPENDENCY_LIBRARY: ""
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- build
|
- build
|
||||||
@@ -14,7 +15,8 @@ stages:
|
|||||||
- cd $BUILD_PADDING_PREFIX/$CI_PROJECT_PATH
|
- cd $BUILD_PADDING_PREFIX/$CI_PROJECT_PATH
|
||||||
- chmod +x ./ci/travis.sh
|
- chmod +x ./ci/travis.sh
|
||||||
script:
|
script:
|
||||||
- yum makecache
|
- wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
|
||||||
|
- yum makecache fast
|
||||||
- ./ci/travis.sh
|
- ./ci/travis.sh
|
||||||
- cd build
|
- cd build
|
||||||
tags:
|
tags:
|
||||||
@@ -26,7 +28,8 @@ branch_build_debug:
|
|||||||
variables:
|
variables:
|
||||||
BUILD_TYPE: Debug
|
BUILD_TYPE: Debug
|
||||||
except:
|
except:
|
||||||
- /^develop.*$/i
|
- /^dev*.*$/i
|
||||||
|
- /^rel*.*$/i
|
||||||
- /^master.*$/i
|
- /^master.*$/i
|
||||||
- tags
|
- tags
|
||||||
|
|
||||||
@@ -36,7 +39,8 @@ branch_build_release:
|
|||||||
BUILD_TYPE: RelWithDebInfo
|
BUILD_TYPE: RelWithDebInfo
|
||||||
extends: .build_by_travis
|
extends: .build_by_travis
|
||||||
except:
|
except:
|
||||||
- /^develop.*$/i
|
- /^dev*.*$/i
|
||||||
|
- /^rel*.*$/i
|
||||||
- /^master.*$/i
|
- /^master.*$/i
|
||||||
- tags
|
- tags
|
||||||
|
|
||||||
@@ -46,12 +50,17 @@ develop_build_debug:
|
|||||||
variables:
|
variables:
|
||||||
BUILD_TYPE: Debug
|
BUILD_TYPE: Debug
|
||||||
PACKAGE: 1
|
PACKAGE: 1
|
||||||
|
UPLOAD_RPM: 1
|
||||||
|
ASAN_OPTION: ADDRESS
|
||||||
|
PULP3_REPO_NAME: framework-testing-x86_64.el7
|
||||||
|
PULP3_DIST_NAME: framework-testing-x86_64.el7
|
||||||
artifacts:
|
artifacts:
|
||||||
name: "MESA_handle_logger-$CI_COMMIT_REF_NAME-debug"
|
name: "MESA_handle_logger-$CI_COMMIT_REF_NAME-debug"
|
||||||
paths:
|
paths:
|
||||||
- build/*.rpm
|
- build/*.rpm
|
||||||
only:
|
only:
|
||||||
- /^develop.*$/i
|
- /^dev*.*$/i
|
||||||
|
- /^rel*.*$/i
|
||||||
- /^master.*$/i
|
- /^master.*$/i
|
||||||
|
|
||||||
develop_build_release:
|
develop_build_release:
|
||||||
@@ -60,21 +69,26 @@ develop_build_release:
|
|||||||
variables:
|
variables:
|
||||||
BUILD_TYPE: RelWithDebInfo
|
BUILD_TYPE: RelWithDebInfo
|
||||||
PACKAGE: 1
|
PACKAGE: 1
|
||||||
|
UPLOAD_RPM: 1
|
||||||
|
ASAN_OPTION: "OFF"
|
||||||
|
PULP3_REPO_NAME: framework-testing-x86_64.el7
|
||||||
|
PULP3_DIST_NAME: framework-testing-x86_64.el7
|
||||||
artifacts:
|
artifacts:
|
||||||
name: "MESA_handle_logger-$CI_COMMIT_REF_NAME-release"
|
name: "MESA_handle_logger-$CI_COMMIT_REF_NAME-release"
|
||||||
paths:
|
paths:
|
||||||
- build/*.rpm
|
- build/*.rpm
|
||||||
only:
|
only:
|
||||||
- /^develop.*$/i
|
- /^dev*.*$/i
|
||||||
|
- /^rel*.*$/i
|
||||||
- /^master.*$/i
|
- /^master.*$/i
|
||||||
|
|
||||||
|
|
||||||
release_build_release:
|
release_build_debug:
|
||||||
stage: build
|
stage: build
|
||||||
variables:
|
variables:
|
||||||
BUILD_TYPE: RelWithDebInfo
|
BUILD_TYPE: Debug
|
||||||
PACKAGE: 1
|
PACKAGE: 1
|
||||||
UPLOAD: 1
|
UPLOAD_RPM: 1
|
||||||
PULP3_REPO_NAME: framework-stable-x86_64.el7
|
PULP3_REPO_NAME: framework-stable-x86_64.el7
|
||||||
PULP3_DIST_NAME: framework-stable-x86_64.el7
|
PULP3_DIST_NAME: framework-stable-x86_64.el7
|
||||||
extends: .build_by_travis
|
extends: .build_by_travis
|
||||||
@@ -84,3 +98,21 @@ release_build_release:
|
|||||||
- build/*.rpm
|
- build/*.rpm
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
|
|
||||||
|
release_build_release:
|
||||||
|
stage: build
|
||||||
|
variables:
|
||||||
|
BUILD_TYPE: RelWithDebInfo
|
||||||
|
PACKAGE: 1
|
||||||
|
UPLOAD_RPM: 1
|
||||||
|
UPLOAD_SYMBOL_FILES: 1
|
||||||
|
SYMBOL_TARGET: libMESA_handle_logger
|
||||||
|
PULP3_REPO_NAME: framework-stable-x86_64.el7
|
||||||
|
PULP3_DIST_NAME: framework-stable-x86_64.el7
|
||||||
|
extends: .build_by_travis
|
||||||
|
artifacts:
|
||||||
|
name: "MESA_handle_logger-$CI_COMMIT_REF_NAME-release"
|
||||||
|
paths:
|
||||||
|
- build/*.rpm
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
@@ -4,64 +4,69 @@ set(lib_name MESA_handle_logger)
|
|||||||
|
|
||||||
project (${lib_name})
|
project (${lib_name})
|
||||||
|
|
||||||
|
set(LIB_MAJOR_VERSION 2)
|
||||||
|
set(LIB_MINOR_VERSION 0)
|
||||||
|
|
||||||
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
|
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
|
||||||
include(Version)
|
include(Version)
|
||||||
|
|
||||||
#SET(CMAKE_C_COMPILER "/usr/bin/g++")
|
|
||||||
set(CMAKE_MACOSX_RPATH 0)
|
set(CMAKE_MACOSX_RPATH 0)
|
||||||
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -Wall)
|
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -Wall)
|
||||||
set(CMAKE_INSTALL_PREFIX /opt/MESA)
|
set(CMAKE_INSTALL_PREFIX /opt/MESA)
|
||||||
|
|
||||||
#for ASAN
|
#for ASAN
|
||||||
set(ASAN_OPTION "OFF" CACHE STRING " set asan type chosen by the user, using OFF as default")
|
option(ENABLE_SANITIZE_ADDRESS "Enable AddressSanitizer" FALSE)
|
||||||
set_property(CACHE ASAN_OPTION PROPERTY STRINGS OFF ADDRESS THREAD)
|
option(ENABLE_SANITIZE_THREAD "Enable ThreadSanitizer" FALSE)
|
||||||
message(STATUS "ASAN_OPTION='${ASAN_OPTION}'")
|
|
||||||
|
|
||||||
if(ASAN_OPTION MATCHES "ADDRESS")
|
if(ENABLE_SANITIZE_ADDRESS)
|
||||||
set(CMAKE_C_FLAGS "${CMAKADDRESS} -g -DCMAKE_BUILD_TYPE=Debug -fsanitize=address -fno-omit-frame-pointer")
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fno-omit-frame-pointer")
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -DCMAKE_BUILD_TYPE=Debug -fsanitize=address -fno-omit-frame-pointer")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer")
|
||||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lasan")
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lasan")
|
||||||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lasan")
|
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lasan")
|
||||||
elseif(ASAN_OPTION MATCHES "THREAD")
|
elseif(ENABLE_SANITIZE_THREAD)
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -DCMAKE_BUILD_TYPE=Debug -fsanitize=thread -fno-omit-frame-pointer")
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=thread -fno-omit-frame-pointer")
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -DCMAKE_BUILD_TYPE=Debug -fsanitize=thread -fno-omit-frame-pointer")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread -fno-omit-frame-pointer")
|
||||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lasan")
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lasan")
|
||||||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lasan")
|
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lasan")
|
||||||
endif()
|
endif()
|
||||||
# end of for ASAN
|
# end of for ASAN
|
||||||
|
|
||||||
include_directories(${PROJECT_SOURCE_DIR}/inc/)
|
include_directories(${PROJECT_SOURCE_DIR}/inc/)
|
||||||
|
|
||||||
file(GLOB SRC
|
add_subdirectory(zlog)
|
||||||
"src/*.c"
|
|
||||||
"src/*.cpp"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Shared Library Output
|
# Shared Library Output
|
||||||
add_library(${lib_name}_shared SHARED ${SRC})
|
add_library(${lib_name}_shared SHARED src/MESA_handle_logger.c)
|
||||||
|
target_link_libraries(${lib_name}_shared zlog_static)
|
||||||
|
set_target_properties(${lib_name}_shared PROPERTIES LINK_FLAGS
|
||||||
|
"-Wl,--version-script=${PROJECT_SOURCE_DIR}/src/version.map")
|
||||||
|
target_link_libraries(${lib_name}_shared pthread)
|
||||||
|
|
||||||
if(DEFINED MESA_SHARED_INSTALL_DIR)
|
if(DEFINED MESA_SHARED_INSTALL_DIR)
|
||||||
set_target_properties(${lib_name}_shared PROPERTIES OUTPUT_NAME ${lib_name} LIBRARY_OUTPUT_DIRECTORY ${MESA_SHARED_INSTALL_DIR})
|
set_target_properties(${lib_name}_shared PROPERTIES OUTPUT_NAME ${lib_name} LIBRARY_OUTPUT_DIRECTORY ${MESA_SHARED_INSTALL_DIR})
|
||||||
else()
|
else()
|
||||||
set_target_properties(${lib_name}_shared PROPERTIES OUTPUT_NAME ${lib_name})
|
set_target_properties(${lib_name}_shared PROPERTIES OUTPUT_NAME ${lib_name})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
set_target_properties(${lib_name}_shared PROPERTIES VERSION ${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION})
|
||||||
|
set_target_properties(${lib_name}_shared PROPERTIES SOVERSION ${LIB_MAJOR_VERSION})
|
||||||
|
|
||||||
# static Library Output
|
# static Library Output
|
||||||
add_library(${lib_name}_static STATIC ${SRC})
|
add_library(${lib_name}_static STATIC src/MESA_handle_logger.c)
|
||||||
|
target_link_libraries(${lib_name}_static zlog_static)
|
||||||
set_target_properties(${lib_name}_static PROPERTIES OUTPUT_NAME ${lib_name})
|
set_target_properties(${lib_name}_static PROPERTIES OUTPUT_NAME ${lib_name})
|
||||||
|
|
||||||
set(CMAKE_INSTALL_PREFIX /opt/MESA)
|
set(CMAKE_INSTALL_PREFIX /opt/MESA)
|
||||||
|
|
||||||
install(TARGETS ${lib_name}_shared LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib COMPONENT LIBRARY)
|
install(FILES inc/MESA_handle_logger.h DESTINATION
|
||||||
install(FILES inc/${lib_name}.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include/MESA COMPONENT HEADER)
|
${CMAKE_INSTALL_PREFIX}/include/MESA COMPONENT devel)
|
||||||
|
install(TARGETS ${lib_name}_shared LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib COMPONENT LIBRARIES)
|
||||||
|
install(FILES inc/MESA_handle_logger.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include/MESA COMPONENT HEADER)
|
||||||
|
install(FILES conf/MESA_handle_logger.conf DESTINATION /usr/lib/tmpfiles.d/ COMPONENT PROFILE)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
file(GLOB DEMO
|
add_executable(${lib_name}_demo demo/test_handle_logger.c)
|
||||||
"demo/*.c"
|
target_link_libraries(${lib_name}_demo pthread ${lib_name}_shared)
|
||||||
"demo/*.cpp"
|
|
||||||
)
|
|
||||||
|
|
||||||
add_executable(${lib_name}_demo ${DEMO})
|
|
||||||
target_link_libraries(${lib_name}_demo rt pthread ${lib_name}_static)
|
|
||||||
|
|
||||||
include(Package)
|
include(Package)
|
||||||
|
|||||||
12
README
12
README
@@ -4,13 +4,19 @@
|
|||||||
*Author:yangwei@iie.ac.cn
|
*Author:yangwei@iie.ac.cn
|
||||||
*History:
|
*History:
|
||||||
2014-03-24 created by yw
|
2014-03-24 created by yw
|
||||||
1)first version
|
1)第一个动态库版本
|
||||||
|
|
||||||
2014-04-16 modified by yw
|
2014-04-16 modified by yw
|
||||||
1)strict inspection parameters, compatible with g++ 4.4.4
|
1) 支持g++ 4.4.4编译
|
||||||
|
|
||||||
2014-05-29 update by yw
|
2014-05-29 update by yw
|
||||||
1)create directory is supported
|
1)支持创建用户指定的日志目录
|
||||||
|
|
||||||
|
2019-2-18 update by yw
|
||||||
|
1)性能优化,句柄中存储文件fp,定期flush至文件
|
||||||
|
|
||||||
|
2020-09-07 update to libMESA_handle_logger2 by yw
|
||||||
|
1)内部使用zlog实现,行为变更,更新库为libMESA_handle_logger2
|
||||||
-------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------
|
||||||
NOTICE:
|
NOTICE:
|
||||||
1)compatible with g++, extern with c;
|
1)compatible with g++, extern with c;
|
||||||
|
|||||||
24
ci/travis.sh
24
ci/travis.sh
@@ -33,7 +33,14 @@ env | sort
|
|||||||
: "${COMPILER_IS_GNUCXX:=OFF}"
|
: "${COMPILER_IS_GNUCXX:=OFF}"
|
||||||
|
|
||||||
# Install dependency from YUM
|
# Install dependency from YUM
|
||||||
#yum install -y mrzcpd framework numactl-devel zlib-devel librdkafka-devel systemd-devel
|
if [ -n "${INSTALL_DEPENDENCY_LIBRARY}" ]; then
|
||||||
|
yum install -y $INSTALL_DEPENDENCY_LIBRARY
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $ASAN_OPTION ];then
|
||||||
|
source /opt/rh/devtoolset-7/enable
|
||||||
|
fi
|
||||||
|
|
||||||
mkdir build || true
|
mkdir build || true
|
||||||
cd build
|
cd build
|
||||||
|
|
||||||
@@ -41,6 +48,8 @@ cmake3 -DCMAKE_CXX_FLAGS=$CXX_FLAGS \
|
|||||||
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
|
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
|
||||||
-DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX \
|
-DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX \
|
||||||
-DENABLE_DEVEL=$ENABLE_DEVEL_SWITCH \
|
-DENABLE_DEVEL=$ENABLE_DEVEL_SWITCH \
|
||||||
|
-DASAN_OPTION=$ASAN_OPTION \
|
||||||
|
-DVERSION_DAILY_BUILD=$TESTING_VERSION_BUILD \
|
||||||
..
|
..
|
||||||
|
|
||||||
make
|
make
|
||||||
@@ -49,13 +58,14 @@ if [ -n "${PACKAGE}" ]; then
|
|||||||
make package
|
make package
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "${UPLOAD}" ]; then
|
if [ -n "${UPLOAD_RPM}" ]; then
|
||||||
cp ~/rpm_upload_tools.py ./
|
cp ~/rpm_upload_tools.py ./
|
||||||
python3 rpm_upload_tools.py ${PULP3_REPO_NAME} ${PULP3_DIST_NAME} *.rpm
|
python3 rpm_upload_tools.py ${PULP3_REPO_NAME} ${PULP3_DIST_NAME} *.rpm
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#if [ -n "${UPLOAD_SYMBOL_FILES}" ]; then
|
if [ -n "${UPLOAD_SYMBOL_FILES}" ]; then
|
||||||
# rpm -i tfe*debuginfo*.rpm
|
rpm -i $SYMBOL_TARGET*debuginfo*.rpm
|
||||||
# cp /usr/lib/debug/opt/tsg/tfe/bin/tfe.debug /tmp/tfe.debuginfo.${CI_COMMIT_SHORT_SHA}
|
_symbol_file=`find /usr/lib/debug/ -name "$SYMBOL_TARGET*.so*.debug"`
|
||||||
# sentry-cli upload-dif -t elf /tmp/tfe.debuginfo.${CI_COMMIT_SHORT_SHA}
|
cp $_symbol_file ${_symbol_file}info.${CI_COMMIT_SHORT_SHA}
|
||||||
#fi
|
sentry-cli upload-dif -t elf ${_symbol_file}info.${CI_COMMIT_SHORT_SHA}
|
||||||
|
fi
|
||||||
@@ -14,6 +14,9 @@ set(CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
|
|||||||
set(CPACK_PACKAGE_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}.${VERSION_BUILD}")
|
set(CPACK_PACKAGE_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}.${VERSION_BUILD}")
|
||||||
execute_process(COMMAND bash -c "echo -ne \"`uname -r | awk -F'.' '{print $5\".\"$6\".\"$7}'`\"" OUTPUT_VARIABLE SYSTEM_VERSION)
|
execute_process(COMMAND bash -c "echo -ne \"`uname -r | awk -F'.' '{print $5\".\"$6\".\"$7}'`\"" OUTPUT_VARIABLE SYSTEM_VERSION)
|
||||||
|
|
||||||
|
execute_process(COMMAND sh changelog.sh ${CMAKE_BINARY_DIR} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/cmake)
|
||||||
|
SET(CPACK_RPM_CHANGELOG_FILE ${CMAKE_BINARY_DIR}/changelog.txt)
|
||||||
|
|
||||||
# RPM Build
|
# RPM Build
|
||||||
set(CPACK_GENERATOR "RPM")
|
set(CPACK_GENERATOR "RPM")
|
||||||
set(CPACK_RPM_PACKAGE_VENDOR "MESA")
|
set(CPACK_RPM_PACKAGE_VENDOR "MESA")
|
||||||
@@ -26,24 +29,28 @@ set(CPACK_RPM_COMPONENT_INSTALL ON)
|
|||||||
set(CPACK_COMPONENTS_IGNORE_GROUPS 1)
|
set(CPACK_COMPONENTS_IGNORE_GROUPS 1)
|
||||||
set(CPACK_COMPONENTS_GROUPING ONE_PER_GROUP)
|
set(CPACK_COMPONENTS_GROUPING ONE_PER_GROUP)
|
||||||
set(CPACK_COMPONENT_HEADER_DISPLAY_NAME "develop")
|
set(CPACK_COMPONENT_HEADER_DISPLAY_NAME "develop")
|
||||||
set(CPACK_COMPONENT_LIBRARY_REQUIRED TRUE)
|
set(CPACK_COMPONENT_LIBRARIES_REQUIRED TRUE)
|
||||||
set(CPACK_COMPONENT_HEADER_REQUIRED TRUE)
|
set(CPACK_COMPONENT_HEADER_REQUIRED TRUE)
|
||||||
set(CPACK_RPM_HEADER_PACKAGE_NAME "${MY_RPM_NAME_PREFIX}-devel")
|
set(CPACK_RPM_HEADER_PACKAGE_NAME "${MY_RPM_NAME_PREFIX}-devel")
|
||||||
set(CPACK_RPM_LIBRARY_PACKAGE_NAME ${MY_RPM_NAME_PREFIX})
|
set(CPACK_RPM_LIBRARIES_PACKAGE_NAME ${MY_RPM_NAME_PREFIX})
|
||||||
|
|
||||||
set(CPACK_RPM_FILE_NAME "${CPACK_RPM_LIBRARY_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${SYSTEM_VERSION}.rpm")
|
set(CPACK_RPM_FILE_NAME "${CPACK_RPM_LIBRARIES_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${SYSTEM_VERSION}.rpm")
|
||||||
set(CPACK_RPM_LIBRARY_DEBUGINFO_FILE_NAME "${CPACK_RPM_LIBRARY_PACKAGE_NAME}-debuginfo-${CPACK_PACKAGE_VERSION}-${SYSTEM_VERSION}.rpm")
|
set(CPACK_RPM_LIBRARIES_DEBUGINFO_FILE_NAME "${CPACK_RPM_LIBRARIES_PACKAGE_NAME}-debuginfo-${CPACK_PACKAGE_VERSION}-${SYSTEM_VERSION}.rpm")
|
||||||
set(CPACK_COMPONENT_LIBRARY_GROUP "library")
|
set(CPACK_COMPONENT_LIBRARIES_GROUP "libraries")
|
||||||
|
set(CPACK_COMPONENT_EXECUTABLE_GROUP "libraries")
|
||||||
|
set(CPACK_COMPONENT_PROFILE_GROUP "libraries")
|
||||||
|
|
||||||
set(CPACK_RPM_HEADER_FILE_NAME "${CPACK_RPM_HEADER_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${SYSTEM_VERSION}.rpm")
|
set(CPACK_RPM_HEADER_FILE_NAME "${CPACK_RPM_HEADER_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${SYSTEM_VERSION}.rpm")
|
||||||
set(CPACK_RPM_HEADER_DEBUGINFO_FILE_NAME "${CPACK_RPM_HEADER_PACKAGE_NAME}-debuginfo-${CPACK_PACKAGE_VERSION}-${SYSTEM_VERSION}.rpm")
|
set(CPACK_RPM_HEADER_DEBUGINFO_FILE_NAME "${CPACK_RPM_HEADER_PACKAGE_NAME}-debuginfo-${CPACK_PACKAGE_VERSION}-${SYSTEM_VERSION}.rpm")
|
||||||
set(CPACK_COMPONENT_HEADER_GROUP "header")
|
set(CPACK_COMPONENT_HEADER_GROUP "header")
|
||||||
|
|
||||||
set(CPACK_RPM_HEADER_PACKAGE_REQUIRES_PRE ${CPACK_RPM_LIBRARY_PACKAGE_NAME})
|
set(CPACK_RPM_HEADER_PACKAGE_REQUIRES_PRE ${CPACK_RPM_LIBRARIES_PACKAGE_NAME})
|
||||||
set(CPACK_RPM_HEADER_PACKAGE_CONFLICTS ${CPACK_RPM_HEADER_PACKAGE_NAME})
|
set(CPACK_RPM_HEADER_PACKAGE_CONFLICTS ${CPACK_RPM_HEADER_PACKAGE_NAME})
|
||||||
|
|
||||||
set(CPACK_COMPONENTS_ALL LIBRARY HEADER)
|
set(CPACK_COMPONENTS_ALL LIBRARIES HEADER EXECUTABLE PROFILE)
|
||||||
|
|
||||||
|
set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE ${CMAKE_SOURCE_DIR}/cmake/PostInstall.in)
|
||||||
|
set(CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE ${CMAKE_SOURCE_DIR}/cmake/PostInstall.in)
|
||||||
|
|
||||||
set(CPACK_BUILD_SOURCE_DIRS "${CMAKE_SOURCE_DIR}")
|
set(CPACK_BUILD_SOURCE_DIRS "${CMAKE_SOURCE_DIR}")
|
||||||
|
|
||||||
|
|||||||
2
cmake/PostInstall.in
Normal file
2
cmake/PostInstall.in
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
ldconfig
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
set(__SOURCE_AUTORESIVISION ${CMAKE_SOURCE_DIR}/autorevision.sh)
|
set(__SOURCE_AUTORESIVISION ${CMAKE_SOURCE_DIR}/autorevision.sh)
|
||||||
set(__AUTORESIVISION ${CMAKE_BINARY_DIR}/autorevision.sh)
|
set(__AUTORESIVISION ${CMAKE_BINARY_DIR}/autorevision.sh)
|
||||||
set(__VERSION_CACHE ${CMAKE_SOURCE_DIR}/version.txt)
|
set(__VERSION_CACHE ${CMAKE_BINARY_DIR}/version.txt)
|
||||||
set(__VERSION_CONFIG ${CMAKE_BINARY_DIR}/version.cmake)
|
set(__VERSION_CONFIG ${CMAKE_BINARY_DIR}/version.cmake)
|
||||||
|
|
||||||
file(COPY ${__SOURCE_AUTORESIVISION} DESTINATION ${CMAKE_BINARY_DIR}
|
file(COPY ${__SOURCE_AUTORESIVISION} DESTINATION ${CMAKE_BINARY_DIR}
|
||||||
@@ -38,16 +38,12 @@ set(VERSION_BUILD "${VCS_SHORT_HASH}")
|
|||||||
# print information
|
# print information
|
||||||
message(STATUS "Version: ${VERSION}-${VERSION_BUILD}")
|
message(STATUS "Version: ${VERSION}-${VERSION_BUILD}")
|
||||||
|
|
||||||
if(NOT DEFINE_GIT_VERSION)
|
option(DEFINE_GIT_VERSION "Set DEFINE_GIT_VERSION to TRUE or FALSE" TRUE)
|
||||||
option(DEFINE_GIT_VERSION "Set DEFINE_GIT_VERSION to OFF" OFF)
|
|
||||||
|
|
||||||
set(GIT_VERSION
|
|
||||||
"${VERSION}-${CMAKE_BUILD_TYPE}-${VERSION_BUILD}-${VCS_BRANCH}-${VCS_TAG}-${VCS_DATE}")
|
|
||||||
string(REGEX REPLACE "[-:+/\\.]" "_" GIT_VERSION ${GIT_VERSION})
|
|
||||||
|
|
||||||
if(DEFINE_GIT_VERSION)
|
if(DEFINE_GIT_VERSION)
|
||||||
add_definitions(-DGIT_VERSION=${GIT_VERSION})
|
set(GIT_VERSION
|
||||||
option(DEFINE_GIT_VERSION "Set DEFINE_GIT_VERSION to OFF" ON)
|
"${VERSION}-${CMAKE_BUILD_TYPE}-${VERSION_BUILD}-${VCS_BRANCH}-${VCS_TAG}-${VCS_DATE}")
|
||||||
endif()
|
string(REGEX REPLACE "[-:+/\\.]" "_" GIT_VERSION ${GIT_VERSION})
|
||||||
|
|
||||||
|
add_definitions(-DGIT_VERSION=${GIT_VERSION})
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
4
cmake/changelog.sh
Normal file
4
cmake/changelog.sh
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
work_path=$1
|
||||||
|
branch=`git status | grep branch | awk '{print $NF}'`
|
||||||
|
git log --branches=$branch --no-merges --date=local --show-signature --pretty="* %ad %an %ae %nhash: %H%ncommit:%n%B" | awk -F"-" '{print "- "$0}' | sed 's/- \*/\*/g' | sed 's/- $//g' | sed 's/-/ -/g' | sed 's/[0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\}//g' > $work_path/changelog.txt
|
||||||
2
conf/MESA_handle_logger.conf
Normal file
2
conf/MESA_handle_logger.conf
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
#Type Path Mode User Group Age Argument
|
||||||
|
d /tmp/MESA_handle_logger/ 0755 - - 1h -
|
||||||
13
demo/demo_zlog.conf
Normal file
13
demo/demo_zlog.conf
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
[global]
|
||||||
|
default format = "%d(%c), %V, %U, %m%n"
|
||||||
|
[levels]
|
||||||
|
DEBUG=10
|
||||||
|
INFO=20
|
||||||
|
FATAL=30
|
||||||
|
[formats]
|
||||||
|
other = "%d(%c), %V, %F, %U, %m%n"
|
||||||
|
[rules]
|
||||||
|
*.=debug "./log/runtimelog_debug.%d(%F)"
|
||||||
|
*.=info "./log/runtimelog_info.%d(%F)"
|
||||||
|
*.=fatal "./log/runtimelog_fatal.%d(%F)"
|
||||||
|
!.* "./log/runtimelog_other.%d(%F)"; other
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
#include "MESA_handle_logger.h"
|
#include "MESA_handle_logger.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <fcntl.h>
|
||||||
#include <stdlib.h>
|
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
void *sample_handle = NULL;
|
void *sample_handle = NULL;
|
||||||
@@ -12,12 +13,15 @@ void *test_handle = NULL;
|
|||||||
#define LOG_NUM 100000
|
#define LOG_NUM 100000
|
||||||
#define MAX_THREAD_NUM 65535
|
#define MAX_THREAD_NUM 65535
|
||||||
|
|
||||||
|
int g_mode = 0;
|
||||||
int g_log_num = 0;
|
int g_log_num = 0;
|
||||||
int g_thread_num = 0;
|
int g_thread_num = 0;
|
||||||
|
int g_log_print_way = 0;
|
||||||
|
const char *g_zlog_conf = NULL;
|
||||||
volatile long g_start_time = 0;
|
volatile long g_start_time = 0;
|
||||||
volatile long g_end_time = 0;
|
volatile long g_end_time = 0;
|
||||||
|
|
||||||
void call_logger(int log_num, int thread_num)
|
void call_logger(int log_num, int thread_num, int way)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
struct timespec start, end;
|
struct timespec start, end;
|
||||||
@@ -37,12 +41,25 @@ void call_logger(int log_num, int thread_num)
|
|||||||
}
|
}
|
||||||
for(i = 0; i < log_num; i++)
|
for(i = 0; i < log_num; i++)
|
||||||
{
|
{
|
||||||
MESA_handle_runtime_log(sample_handle, RLOG_LV_INFO, "sample", "sample_handle MESA_handle_runtime_log, i = %d, thread_num = %d", i, thread_num);
|
switch (way)
|
||||||
//sleep(1);
|
{
|
||||||
|
case 1:
|
||||||
|
MESA_handle_runtime_log(sample_handle, RLOG_LV_DEBUG, "sample", "sample_handle RUNTIEM_LOG test, i = %d, thread_num = %d", i, thread_num);
|
||||||
MESA_handle_runtime_log(test_handle, RLOG_LV_INFO, "test", "test_handle MESA_handle_runtime_log, i = %d, thread_num = %d", i, thread_num);
|
MESA_handle_runtime_log(test_handle, RLOG_LV_INFO, "test", "test_handle MESA_handle_runtime_log, i = %d, thread_num = %d", i, thread_num);
|
||||||
//MESA_HANDLE_RUNTIME_LOG(sample_handle, RLOG_LV_FATAL, "sample", "sample_handle RUNTIEM_LOG test, i = %d, thread_num = %d", i, thread_num);
|
break;
|
||||||
////sleep(1);
|
case 2:
|
||||||
//MESA_HANDLE_RUNTIME_LOG(test_handle, RLOG_LV_FATAL, "test", "test_handle RUNTIEM_LOG test, i = %d, thread_num = %d", i, thread_num);
|
MESA_HANDLE_RUNTIME_LOG_RATELIMIT(sample_handle, RLOG_LV_DEBUG, "sample", "sample_handle RUNTIEM_LOG test, i = %d, thread_num = %d", i, thread_num);
|
||||||
|
MESA_HANDLE_RUNTIME_LOG_RATELIMIT(test_handle, RLOG_LV_INFO, "test", "test_handle RUNTIEM_LOG test, i = %d, thread_num = %d", i, thread_num);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
MESA_HANDLE_RUNTIME_LOG(sample_handle, RLOG_LV_DEBUG, "sample", "sample_handle RUNTIEM_LOG test, i = %d, thread_num = %d", i, thread_num);
|
||||||
|
MESA_HANDLE_RUNTIME_LOG(test_handle, RLOG_LV_INFO, "test", "test_handle RUNTIEM_LOG test, i = %d, thread_num = %d", i, thread_num);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// if (i % 10000 == 0)
|
||||||
|
// sleep(1);
|
||||||
}
|
}
|
||||||
clock_gettime(CLOCK_MONOTONIC, &end);
|
clock_gettime(CLOCK_MONOTONIC, &end);
|
||||||
end_time = end.tv_sec*1000000 + end.tv_nsec/1000;
|
end_time = end.tv_sec*1000000 + end.tv_nsec/1000;
|
||||||
@@ -67,41 +84,80 @@ void *thread_logger(void *arg)
|
|||||||
{
|
{
|
||||||
int thread_num = (int)(unsigned long long)arg;
|
int thread_num = (int)(unsigned long long)arg;
|
||||||
printf("thread %d created! \n", thread_num);
|
printf("thread %d created! \n", thread_num);
|
||||||
call_logger(g_log_num, thread_num);
|
call_logger(g_log_num, thread_num, g_log_print_way);
|
||||||
printf("thread %d finished! \n", thread_num);
|
printf("thread %d finished! \n", thread_num);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sig_handler(int sig)
|
void sig_int_handler(int sig)
|
||||||
{
|
{
|
||||||
printf("ctrl+c recviced!\n");
|
printf("ctrl+c recviced!\n");
|
||||||
MESA_destroy_runtime_log_handle(sample_handle);
|
MESA_destroy_runtime_log_handle(sample_handle);
|
||||||
MESA_destroy_runtime_log_handle(test_handle);
|
MESA_destroy_runtime_log_handle(test_handle);
|
||||||
sample_handle = NULL;
|
sample_handle = NULL;
|
||||||
test_handle = NULL;
|
test_handle = NULL;
|
||||||
printf("%d thread write %d log using %ld us, avg speed %f /s, %ld -> %ld\n", g_thread_num, g_thread_num*g_log_num, g_end_time-g_start_time, ((float)(g_thread_num*g_log_num)/(float)(g_end_time-g_start_time))*1000000, g_start_time, g_end_time);
|
if (g_mode == 2)
|
||||||
|
{
|
||||||
|
MESA_handle_runtime_log_destruction();
|
||||||
|
}
|
||||||
|
printf("%d thread write %d log using %ld us, avg speed %f /s, %ld -> %ld\n", g_thread_num, g_thread_num * g_log_num, g_end_time - g_start_time, ((float)(g_thread_num * g_log_num) / (float)(g_end_time - g_start_time)) * 1000000, g_start_time, g_end_time);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sig_hup_handler(int sig)
|
||||||
|
{
|
||||||
|
printf("SIGHUP recviced!\n");
|
||||||
|
MESA_handle_runtime_log_reconstruction(g_zlog_conf);
|
||||||
|
}
|
||||||
|
|
||||||
|
void sig_user1_handler(int sig)
|
||||||
|
{
|
||||||
|
printf("SIGUSR1 recviced! set interval:3 burst:5\n");
|
||||||
|
MESA_set_runtime_log_handle_ratelimit(sample_handle, 3, 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
void sig_user2_handler(int sig)
|
||||||
|
{
|
||||||
|
printf("SIGUSR2 recviced! set interval:5 burst:3\n");
|
||||||
|
MESA_set_runtime_log_handle_ratelimit(sample_handle, 5, 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
void sig_min_handler(int sig)
|
||||||
|
{
|
||||||
|
printf("SIGRTMIN recviced! unlimit\n");
|
||||||
|
MESA_set_runtime_log_handle_ratelimit(sample_handle, 0, 3);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char ** args)
|
int main(int argc, char ** args)
|
||||||
{
|
{
|
||||||
pthread_t t[MAX_THREAD_NUM];
|
pthread_t t[MAX_THREAD_NUM];
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
if(argc != 3)
|
if (argc != 6)
|
||||||
{
|
{
|
||||||
printf("Usage: ./($app) $thread_num $log_num \n");
|
printf("Usage: ./($app) $mode[1 or 2] $zlog_conf_path $thread_num $log_num $log_print_way[1 2 3]\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
g_thread_num = atoi(args[1]);
|
g_mode = atoi(args[1]);
|
||||||
g_log_num = atoi(args[2]);
|
g_zlog_conf = args[2];
|
||||||
|
g_thread_num = atoi(args[3]);
|
||||||
|
g_log_num = atoi(args[4]);
|
||||||
|
g_log_print_way = atoi(args[5]);
|
||||||
|
|
||||||
if(g_thread_num <= 0 || g_log_num <= 0)
|
if(g_thread_num <= 0 || g_log_num <= 0)
|
||||||
{
|
{
|
||||||
printf("Error, wrong parameter!\n");
|
printf("Error, wrong parameter!\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
sample_handle = MESA_create_runtime_log_handle("./log/test_log", RLOG_LV_DEBUG);
|
if (g_mode == 2)
|
||||||
|
{
|
||||||
|
if (0 != MESA_handle_runtime_log_creation(g_zlog_conf))
|
||||||
|
{
|
||||||
|
printf("MESA_handle_runtime_log_creation return error\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sample_handle = MESA_create_runtime_log_handle("./log/sample_log", RLOG_LV_DEBUG);
|
||||||
if (sample_handle == NULL)
|
if (sample_handle == NULL)
|
||||||
{
|
{
|
||||||
printf("get log sample_handle error\n");
|
printf("get log sample_handle error\n");
|
||||||
@@ -119,7 +175,11 @@ int main(int argc, char ** args)
|
|||||||
{
|
{
|
||||||
pthread_create(&t[i], NULL, thread_logger, (void *)(unsigned long)(i));
|
pthread_create(&t[i], NULL, thread_logger, (void *)(unsigned long)(i));
|
||||||
}
|
}
|
||||||
signal(SIGINT, sig_handler);
|
signal(SIGINT, sig_int_handler);
|
||||||
|
signal(SIGHUP, sig_hup_handler);
|
||||||
|
signal(SIGUSR1, sig_user1_handler);
|
||||||
|
signal(SIGUSR2, sig_user2_handler);
|
||||||
|
signal(SIGRTMIN, sig_min_handler);
|
||||||
while(1)
|
while(1)
|
||||||
;
|
;
|
||||||
//MESA_destroy_runtime_log_handle(sample_handle);
|
//MESA_destroy_runtime_log_handle(sample_handle);
|
||||||
|
|||||||
@@ -14,16 +14,40 @@ extern "C"
|
|||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
#define RLOG_LV_DEBUG 10
|
#define RLOG_LV_DEBUG 10
|
||||||
#define RLOG_LV_INFO 20
|
#define RLOG_LV_INFO 20
|
||||||
#define RLOG_LV_FATAL 30
|
#define RLOG_LV_FATAL 30
|
||||||
|
|
||||||
|
typedef struct log_ratelimit_s
|
||||||
|
{
|
||||||
|
int interval;
|
||||||
|
int burst;
|
||||||
|
int printed;
|
||||||
|
int missed;
|
||||||
|
long begin;
|
||||||
|
pthread_mutex_t mutex;
|
||||||
|
}log_ratelimit_t;
|
||||||
|
|
||||||
|
int MESA_handle_runtime_log_creation(const char *conf_path);
|
||||||
|
int MESA_handle_runtime_log_reconstruction(const char *conf_path);
|
||||||
|
void MESA_handle_runtime_log_destruction();
|
||||||
|
|
||||||
#define MESA_HANDLE_RUNTIME_LOG(handle, lv, mod, fmt, args...) \
|
#define MESA_HANDLE_RUNTIME_LOG(handle, lv, mod, fmt, args...) \
|
||||||
MESA_handle_runtime_log((handle), (lv), (mod), "file %s, line %d, " fmt, \
|
MESA_handle_runtime_log((handle), (lv), (mod), "file %s, line %d, " fmt, \
|
||||||
__FILE__, __LINE__, ##args)
|
__FILE__, __LINE__, ##args)
|
||||||
|
|
||||||
/*
|
#define MESA_HANDLE_RUNTIME_LOG_RATELIMIT(handle, lv, mod, fmt, args...) \
|
||||||
|
({ \
|
||||||
|
static log_ratelimit_t _rs = { \
|
||||||
|
.mutex = PTHREAD_MUTEX_INITIALIZER, \
|
||||||
|
}; \
|
||||||
|
if (MESA_runtime_log_ratelimit((handle), (&_rs), (lv), (mod), (__func__))) \
|
||||||
|
MESA_handle_runtime_log((handle), (lv), (mod), fmt, ##args); \
|
||||||
|
})
|
||||||
|
|
||||||
|
/*
|
||||||
* name: MESA_create_runtime_log_handle
|
* name: MESA_create_runtime_log_handle
|
||||||
* functionality: get runtime_log handle;
|
* functionality: get runtime_log handle;
|
||||||
* params:
|
* params:
|
||||||
@@ -33,7 +57,7 @@ extern "C"
|
|||||||
* not NULL, if succeeded;
|
* not NULL, if succeeded;
|
||||||
* NULL, if file is not absolute path, or failed to create log file;
|
* NULL, if file is not absolute path, or failed to create log file;
|
||||||
*/
|
*/
|
||||||
void *MESA_create_runtime_log_handle(const char *file_path, int level);
|
void *MESA_create_runtime_log_handle(const char *file_path, int level);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* name: MESA_handle_runtime_log
|
* name: MESA_handle_runtime_log
|
||||||
@@ -59,6 +83,18 @@ void MESA_handle_runtime_log(void *handle, int level, const char *module, const
|
|||||||
*/
|
*/
|
||||||
void MESA_destroy_runtime_log_handle(void *handle);
|
void MESA_destroy_runtime_log_handle(void *handle);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* name: MESA_set_runtime_log_handle_ratelimit
|
||||||
|
* functionality: set not more than @burst in every @interval when appends log message
|
||||||
|
* params:
|
||||||
|
* handle: runtime log handle which is going to be released;
|
||||||
|
* interval: interval time(second). if set '0', it means unlimit.
|
||||||
|
* burst: in interval time max count
|
||||||
|
* returns:
|
||||||
|
* none;
|
||||||
|
*/
|
||||||
|
void MESA_set_runtime_log_handle_ratelimit(void *handle, int interval, int burst);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,24 +1,38 @@
|
|||||||
#include "MESA_handle_logger.h"
|
#include "MESA_handle_logger.h"
|
||||||
|
#include "zlog.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <fcntl.h>
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include<sys/stat.h>
|
#include <time.h>
|
||||||
|
|
||||||
|
#define MAX_HANDLE_LOG_PATH 4096
|
||||||
|
#define DEFAULT_BURST 10
|
||||||
|
#define DEFAULT_INTERVAL 5
|
||||||
|
|
||||||
|
static int g_zlog_inited = 0;
|
||||||
|
static int g_zlog_conf_fp = -1;
|
||||||
|
static char global_conf_filepath[MAX_HANDLE_LOG_PATH] = "";
|
||||||
|
static char tmp_conf_filepath[MAX_HANDLE_LOG_PATH] = "";
|
||||||
|
|
||||||
typedef struct log_handle_t
|
typedef struct log_handle_t
|
||||||
{
|
{
|
||||||
|
int interval;
|
||||||
|
int burst;
|
||||||
|
pthread_mutex_t mutex;
|
||||||
int runtime_log_level;
|
int runtime_log_level;
|
||||||
char runtime_log_file[1200];
|
zlog_category_t *zc;
|
||||||
|
const char *global_conf_path;
|
||||||
|
char runtime_log_file[MAX_HANDLE_LOG_PATH];
|
||||||
} log_handle_t;
|
} log_handle_t;
|
||||||
|
|
||||||
#define THREAD_CTIME(t, buf, len) thread_safe_ctime(t, buf, len)
|
|
||||||
#define LOGMSG_MAX_LEN 4096
|
|
||||||
|
|
||||||
//const int HANDLE_LOGGER_VERSION_20170816 = 1;
|
|
||||||
#define GIT_VERSION_CATTER(v) __attribute__((__used__)) const char *GIT_VERSION_##v = NULL
|
//const int HANDLE_LOGGER_VERSION_20190218 = 1;
|
||||||
|
|
||||||
|
#define GIT_VERSION_CATTER(v) __attribute__((__used__)) const char * GIT_VERSION_##v = NULL
|
||||||
#define GIT_VERSION_EXPEND(v) GIT_VERSION_CATTER(v)
|
#define GIT_VERSION_EXPEND(v) GIT_VERSION_CATTER(v)
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
@@ -28,9 +42,9 @@ extern "C"
|
|||||||
|
|
||||||
/* VERSION TAG */
|
/* VERSION TAG */
|
||||||
#ifdef GIT_VERSION
|
#ifdef GIT_VERSION
|
||||||
GIT_VERSION_EXPEND(GIT_VERSION);
|
GIT_VERSION_EXPEND(GIT_VERSION);
|
||||||
#else
|
#else
|
||||||
static __attribute__((__used__)) const char *GIT_VERSION_UNKNOWN = NULL;
|
static __attribute__((__used__)) const char * GIT_VERSION_UNKNOWN = NULL;
|
||||||
#endif
|
#endif
|
||||||
#undef GIT_VERSION_CATTER
|
#undef GIT_VERSION_CATTER
|
||||||
#undef GIT_VERSION_EXPEND
|
#undef GIT_VERSION_EXPEND
|
||||||
@@ -39,53 +53,6 @@ static __attribute__((__used__)) const char *GIT_VERSION_UNKNOWN = NULL;
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static unsigned int month_days[12] =
|
|
||||||
{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
|
||||||
|
|
||||||
static unsigned char weekday_str[7][4] =
|
|
||||||
{"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
|
|
||||||
|
|
||||||
static unsigned char month_str[12][4] = {"Jan", "Feb", "Mar", "Apr",
|
|
||||||
"May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
|
|
||||||
|
|
||||||
char *thread_safe_ctime(const time_t *tp, char *buf, int len)
|
|
||||||
{
|
|
||||||
unsigned int year, month, day, weekday, hour, min, sec;
|
|
||||||
unsigned int year_days = 365;
|
|
||||||
sec = * tp;
|
|
||||||
min = sec / 60; sec = sec % 60;
|
|
||||||
hour = min / 60; min = min % 60; hour += 8;
|
|
||||||
day = hour / 24; hour = hour % 24;
|
|
||||||
weekday = day % 7; weekday = (weekday + 4) % 7;
|
|
||||||
|
|
||||||
for(year = 1970; day >= year_days;)
|
|
||||||
{
|
|
||||||
day -= year_days;
|
|
||||||
year ++;
|
|
||||||
|
|
||||||
if(0 == year % 4 && (0 != year % 100 || 0 == year % 400))
|
|
||||||
year_days = 366;
|
|
||||||
else year_days = 365;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(366 == year_days) month_days[1] = 29;
|
|
||||||
|
|
||||||
//bug fix by yw 20120808
|
|
||||||
for(month = 0; day >= month_days[month];)
|
|
||||||
{
|
|
||||||
day -= month_days[month];
|
|
||||||
month ++;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
snprintf(buf, len, "%02d:%02d:%02d, %04d/%02d/%02d, %s",
|
|
||||||
hour, min, sec, year, month, day, weekday_str[week_day]);
|
|
||||||
*/
|
|
||||||
snprintf(buf, len, "%s %s %d %02d:%02d:%02d %d", weekday_str[weekday],
|
|
||||||
month_str[month], day + 1, hour, min, sec, year);
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int create_dir(const char *dir_path, int path_len)
|
static int create_dir(const char *dir_path, int path_len)
|
||||||
{
|
{
|
||||||
if(dir_path == NULL)
|
if(dir_path == NULL)
|
||||||
@@ -128,41 +95,182 @@ static int create_path(const char *path, int path_len)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int get_filepath(int fp, char *buf, int buflen)
|
||||||
|
{
|
||||||
|
if(buf == NULL || buflen <=0)return -1;
|
||||||
|
char proclnk[0xFFF] = "";
|
||||||
|
int fno = fp;
|
||||||
|
sprintf(proclnk, "/proc/self/fd/%d", fno);
|
||||||
|
int r = readlink(proclnk, buf, buflen);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
//static char tmp_template[] = "/tmp/MESA_handle_loggger/handle_loggger.XXXXXX";
|
||||||
|
|
||||||
|
static void escape_for_zlog(char *in_buf, int buflen)
|
||||||
|
{
|
||||||
|
if(in_buf == NULL || buflen <= 0)return;
|
||||||
|
int i = 0;
|
||||||
|
for(i = 0; i < buflen; i++)
|
||||||
|
{
|
||||||
|
if ((!isalnum(in_buf[i])) && (in_buf[i] != '_') && (in_buf[i] != '-') && (in_buf[i] != '*') && (in_buf[i] != '!'))
|
||||||
|
{
|
||||||
|
in_buf[i] = '_';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char *loglevel_to_name(int level)
|
||||||
|
{
|
||||||
|
if (level <= RLOG_LV_DEBUG)
|
||||||
|
return "DEBUG";
|
||||||
|
if (level > RLOG_LV_DEBUG && level <= RLOG_LV_INFO)
|
||||||
|
return "INFO";
|
||||||
|
return "FATAL";
|
||||||
|
}
|
||||||
|
|
||||||
|
static void snapshot_handle_info(const char *handle_name, const char *log_path, int level)
|
||||||
|
{
|
||||||
|
char zlog_rule_conf_content[MAX_HANDLE_LOG_PATH + 1] = "";
|
||||||
|
static char *tmp_prefix = "/tmp/MESA_handle_logger/";
|
||||||
|
static char *zlog_conf_init_buff = "[global]\ndefault format = \"%d(%c), %V, %F, %U, %m%n\" \n[levels]\nDEBUG=10\nINFO=20\nFATAL=30\n[rules]";
|
||||||
|
if (g_zlog_conf_fp == -1)
|
||||||
|
{
|
||||||
|
if (create_path("/tmp/MESA_handle_logger/", strlen(tmp_prefix)) < 0)
|
||||||
|
return;
|
||||||
|
char temp_filename[1024] = "";
|
||||||
|
sprintf(temp_filename, "/tmp/MESA_handle_logger/MESA_logger_snapshot_%d.XXXXXX", getpid());
|
||||||
|
g_zlog_conf_fp = mkstemp(temp_filename);
|
||||||
|
if (g_zlog_conf_fp == -1)
|
||||||
|
{
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
if (get_filepath(g_zlog_conf_fp, tmp_conf_filepath, sizeof(tmp_conf_filepath)) < 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
write(g_zlog_conf_fp, zlog_conf_init_buff, strlen(zlog_conf_init_buff));
|
||||||
|
fsync(g_zlog_conf_fp);
|
||||||
|
}
|
||||||
|
snprintf(zlog_rule_conf_content, sizeof(zlog_rule_conf_content),
|
||||||
|
"\n%s.%s \"%s.%%d(%%F)\"",
|
||||||
|
handle_name, loglevel_to_name(level), log_path);
|
||||||
|
write(g_zlog_conf_fp, zlog_rule_conf_content, strlen(zlog_rule_conf_content));
|
||||||
|
fsync(g_zlog_conf_fp);
|
||||||
|
|
||||||
|
if(g_zlog_inited == 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"[snapshot_handle_info], Nobody call MESA_handle_runtime_log_creation before, Using (%s) to init zlog, handle_name(%s), log_path(%s), log_level(%d)!!!\n", tmp_conf_filepath, handle_name, log_path, level);
|
||||||
|
zlog_init(tmp_conf_filepath);
|
||||||
|
zlog_reload(NULL);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void log_update_time(log_handle_t *p_handle, log_ratelimit_t *rs, int level, const char *module, const char *func)
|
||||||
|
{
|
||||||
|
struct timespec current = {0, 0};
|
||||||
|
clock_gettime(CLOCK_MONOTONIC, ¤t);
|
||||||
|
if (((long)(rs->begin + rs->interval - current.tv_sec)) < 0)
|
||||||
|
{
|
||||||
|
if (rs->missed)
|
||||||
|
{
|
||||||
|
zlog(p_handle->zc, p_handle->runtime_log_file, strlen(p_handle->runtime_log_file), module, strlen(module), __LINE__, level, "%s: %d callbacks suppressed\n", func, rs->missed);
|
||||||
|
rs->missed = 0;
|
||||||
|
}
|
||||||
|
rs->begin = current.tv_sec;
|
||||||
|
rs->printed = 0;
|
||||||
|
}
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
|
int MESA_runtime_log_ratelimit(void *handle, log_ratelimit_t *rs, int level, const char *module, const char *func)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
struct timespec timer = {0, 0};
|
||||||
|
log_handle_t *p_handle = (log_handle_t *)handle;
|
||||||
|
|
||||||
|
if (pthread_mutex_lock(&rs->mutex) != 0)return 0;
|
||||||
|
|
||||||
|
if (!rs->begin)
|
||||||
|
{
|
||||||
|
clock_gettime(CLOCK_MONOTONIC, &timer);
|
||||||
|
rs->begin = timer.tv_sec;
|
||||||
|
}
|
||||||
|
rs->burst = p_handle->burst;
|
||||||
|
rs->interval = p_handle->interval;
|
||||||
|
if (!rs->interval)
|
||||||
|
{
|
||||||
|
pthread_mutex_unlock(&rs->mutex);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
log_update_time(p_handle, rs, level, module, func);
|
||||||
|
|
||||||
|
if (rs->burst && rs->burst > rs->printed)
|
||||||
|
{
|
||||||
|
rs->printed++;
|
||||||
|
ret = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rs->missed++;
|
||||||
|
ret = 0;
|
||||||
|
}
|
||||||
|
pthread_mutex_unlock(&rs->mutex);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
void *MESA_create_runtime_log_handle(const char *file_path, int level)
|
void *MESA_create_runtime_log_handle(const char *file_path, int level)
|
||||||
{
|
{
|
||||||
if(file_path == NULL)
|
if(file_path == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
int rc = -1;
|
||||||
|
zlog_category_t *zc = NULL;
|
||||||
FILE *fp = NULL;
|
FILE *fp = NULL;
|
||||||
log_handle_t *p_handle = NULL;
|
log_handle_t *p_handle = NULL;
|
||||||
|
|
||||||
//creating file_path failed, return NULL
|
char handle_name[MAX_HANDLE_LOG_PATH];
|
||||||
char *p_path = rindex(file_path, '/');
|
char *p_path_end = rindex(file_path, '/');
|
||||||
if(p_path != 0)
|
char *p_name = p_path_end+1;
|
||||||
{
|
|
||||||
if(create_path(file_path, p_path - file_path) < 0)
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
if(NULL == (fp = fopen(file_path, "w")))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
fclose(fp);
|
strcpy(handle_name, file_path);
|
||||||
//remove(file_path);
|
escape_for_zlog(handle_name, strlen(handle_name));
|
||||||
|
p_name = handle_name;
|
||||||
|
|
||||||
|
|
||||||
|
if(p_path_end != NULL && p_path_end > file_path)
|
||||||
|
{
|
||||||
|
//creating file_path failed, return NULL
|
||||||
|
if (create_path(file_path, p_path_end-file_path) < 0)
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
snapshot_handle_info(p_name, file_path, level);
|
||||||
|
zlog_reload(NULL);
|
||||||
|
zc = zlog_get_category(p_name);
|
||||||
|
if (!zc)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"[MESA_create_runtime_log_handle], get zlog category (%s) in global_conf_filepath(%s) fail\n", p_name, global_conf_filepath);
|
||||||
|
}
|
||||||
p_handle = (log_handle_t *)calloc(sizeof(log_handle_t), 1);
|
p_handle = (log_handle_t *)calloc(sizeof(log_handle_t), 1);
|
||||||
|
strncpy(p_handle->runtime_log_file, file_path, sizeof(p_handle->runtime_log_file) - 1);
|
||||||
if(p_handle == NULL)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
strncpy(p_handle->runtime_log_file, file_path, 1024);
|
|
||||||
p_handle->runtime_log_file[1024] = '\0';
|
|
||||||
p_handle->runtime_log_level = level;
|
p_handle->runtime_log_level = level;
|
||||||
|
p_handle->zc = zc;
|
||||||
|
p_handle->burst = DEFAULT_BURST;
|
||||||
|
p_handle->interval = DEFAULT_INTERVAL;
|
||||||
|
pthread_mutex_init(&p_handle->mutex, NULL);
|
||||||
|
|
||||||
return (void *)p_handle;
|
return (void *)p_handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MESA_destroy_runtime_log_handle(void *handle)
|
void MESA_destroy_runtime_log_handle(void *handle)
|
||||||
{
|
{
|
||||||
|
log_handle_t *p_handle = (log_handle_t *)handle;
|
||||||
if(handle != NULL)
|
if(handle != NULL)
|
||||||
{
|
{
|
||||||
|
pthread_mutex_destroy(&p_handle->mutex);
|
||||||
free(handle);
|
free(handle);
|
||||||
handle = NULL;
|
handle = NULL;
|
||||||
}
|
}
|
||||||
@@ -172,71 +280,127 @@ void MESA_destroy_runtime_log_handle(void *handle)
|
|||||||
|
|
||||||
void MESA_handle_runtime_log(void *handle, int level, const char *module, const char *fmt, ...)
|
void MESA_handle_runtime_log(void *handle, int level, const char *module, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
char buf[LOGMSG_MAX_LEN + 1];
|
|
||||||
time_t t;
|
|
||||||
int len;
|
|
||||||
va_list ap;
|
va_list ap;
|
||||||
FILE *fp;
|
|
||||||
struct tm local_time;
|
|
||||||
char tmp_log_file_name[1201];
|
|
||||||
log_handle_t *p_handle = (log_handle_t *)handle;
|
log_handle_t *p_handle = (log_handle_t *)handle;
|
||||||
|
|
||||||
if(p_handle == NULL || p_handle->runtime_log_file == NULL)return;
|
if(p_handle == NULL || p_handle->runtime_log_file == NULL)return;
|
||||||
|
|
||||||
if(level < p_handle->runtime_log_level) return;
|
if(p_handle->zc == NULL)return;
|
||||||
|
|
||||||
time(&t);
|
|
||||||
if(NULL == (localtime_r(&t, &local_time))) return;
|
|
||||||
//THREAD_CTIME(&t, buf, LOGMSG_MAX_LEN);
|
|
||||||
len = snprintf(buf, sizeof(buf), "%s %s %d %02d:%02d:%02d %d", weekday_str[local_time.tm_wday],
|
|
||||||
month_str[local_time.tm_mon], local_time.tm_mday, local_time.tm_hour, local_time.tm_min, local_time.tm_sec, local_time.tm_year+1900);
|
|
||||||
//len = strlen(buf);
|
|
||||||
|
|
||||||
switch(level)
|
|
||||||
{
|
|
||||||
case RLOG_LV_DEBUG:
|
|
||||||
len += snprintf(buf + len,
|
|
||||||
LOGMSG_MAX_LEN - len, ", %s, ", "DEBUG");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case RLOG_LV_INFO:
|
|
||||||
len += snprintf(buf + len,
|
|
||||||
LOGMSG_MAX_LEN - len, ", %s, ", "INFO");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case RLOG_LV_FATAL:
|
|
||||||
len += snprintf(buf + len,
|
|
||||||
LOGMSG_MAX_LEN - len, ", %s, ", "FATAL");
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
len += snprintf(buf + len,
|
|
||||||
LOGMSG_MAX_LEN - len, ", %s, ", "UNKNOWN");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(0 >= LOGMSG_MAX_LEN - len) return;
|
|
||||||
|
|
||||||
len += snprintf(buf + len, LOGMSG_MAX_LEN - len, "%s, ", module);
|
|
||||||
|
|
||||||
if(0 >= LOGMSG_MAX_LEN - len) return;
|
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
len += vsnprintf(buf + len, LOGMSG_MAX_LEN - len, fmt, ap);
|
vzlog(p_handle->zc, p_handle->runtime_log_file, strlen(p_handle->runtime_log_file), module, strlen(module), __LINE__, level, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
if(0 >= LOGMSG_MAX_LEN - len) return;
|
return ;
|
||||||
|
|
||||||
len += snprintf(buf + len, LOGMSG_MAX_LEN - len, "\n");
|
|
||||||
|
|
||||||
|
|
||||||
sprintf(tmp_log_file_name, "%s.%04d-%02d-%02d", p_handle->runtime_log_file,
|
|
||||||
local_time.tm_year + 1900, local_time.tm_mon + 1,
|
|
||||||
local_time.tm_mday);
|
|
||||||
|
|
||||||
if(NULL == (fp = fopen(tmp_log_file_name, "a"))) return;
|
|
||||||
|
|
||||||
fprintf(fp, "%s", buf);
|
|
||||||
fclose(fp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MESA_set_runtime_log_handle_ratelimit(void *handle, int interval, int burst)
|
||||||
|
{
|
||||||
|
log_handle_t *p_handle = (log_handle_t *)handle;
|
||||||
|
|
||||||
|
if ((p_handle == NULL) || (interval < 0) || (burst < 0))return;
|
||||||
|
|
||||||
|
pthread_mutex_lock(&p_handle->mutex);
|
||||||
|
p_handle->interval = interval;
|
||||||
|
p_handle->burst = burst;
|
||||||
|
pthread_mutex_unlock(&p_handle->mutex);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int MESA_handle_runtime_log_creation(const char *conf_path)
|
||||||
|
{
|
||||||
|
char *env = getenv("ZLOG_CONF_PATH");
|
||||||
|
int rc = 0;
|
||||||
|
if (conf_path == NULL || (access(conf_path, R_OK) != 0))
|
||||||
|
{
|
||||||
|
fprintf(stderr,"[MESA_handle_runtime_log_creation], PATH (%s) unable to access, will output log to STDOUT or Using ZLOG_CONF_PATH (%s) !\n", conf_path, env);
|
||||||
|
rc = zlog_init(NULL);
|
||||||
|
if (rc)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"[MESA_handle_runtime_log_creation], INIT zlog by (NULL) or (%s) failed !!! \n", env);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (env != NULL)
|
||||||
|
{
|
||||||
|
strcpy(global_conf_filepath, env);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rc = zlog_init(conf_path);
|
||||||
|
if (rc)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"[MESA_handle_runtime_log_creation], INIT zlog by (%s) failed , using [NULL] retry !\n", conf_path);
|
||||||
|
rc = zlog_init(NULL);
|
||||||
|
if (rc)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"[MESA_handle_runtime_log_creation], INIT zlog by (NULL) or (%s) failed \n", env);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(env != NULL)
|
||||||
|
{
|
||||||
|
strcpy(global_conf_filepath, env);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
strcpy(global_conf_filepath, conf_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
fprintf(stderr,"[MESA_handle_runtime_log_creation], INIT zlog finish, Using (%s). \n", global_conf_filepath);
|
||||||
|
g_zlog_inited = 1;
|
||||||
|
zlog_profile();
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
int MESA_handle_runtime_log_reconstruction(const char *conf_path)
|
||||||
|
{
|
||||||
|
int rc = zlog_reload(conf_path);
|
||||||
|
#ifdef DEBUG
|
||||||
|
char zlog_rule_conf_content[MAX_HANDLE_LOG_PATH + 1];
|
||||||
|
time_t t;
|
||||||
|
struct tm local_time;
|
||||||
|
static unsigned char weekday_str[7][4] =
|
||||||
|
{"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
|
||||||
|
|
||||||
|
static unsigned char month_str[12][4] = {"Jan", "Feb", "Mar", "Apr",
|
||||||
|
"May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
|
||||||
|
if (!rc)
|
||||||
|
{
|
||||||
|
strcpy(global_conf_filepath, conf_path);
|
||||||
|
zlog_profile();
|
||||||
|
if (g_zlog_conf_fp != -1)
|
||||||
|
{
|
||||||
|
time(&t);
|
||||||
|
if (NULL != (localtime_r(&t, &local_time)))
|
||||||
|
{
|
||||||
|
snprintf(zlog_rule_conf_content, sizeof(zlog_rule_conf_content),
|
||||||
|
"\n%s %s %d %02d:%02d:%02d %d, RECONSTRUCTION to %s\n", weekday_str[local_time.tm_wday],
|
||||||
|
month_str[local_time.tm_mon], local_time.tm_mday, local_time.tm_hour, local_time.tm_min, local_time.tm_sec, local_time.tm_year + 1900, conf_path);
|
||||||
|
write(g_zlog_conf_fp, zlog_rule_conf_content, strlen(zlog_rule_conf_content));
|
||||||
|
fsync(g_zlog_conf_fp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MESA_handle_runtime_log_destruction()
|
||||||
|
{
|
||||||
|
zlog_fini();
|
||||||
|
if (g_zlog_conf_fp != -1)
|
||||||
|
{
|
||||||
|
unlink(tmp_conf_filepath);
|
||||||
|
close(g_zlog_conf_fp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
4
src/version.map
Normal file
4
src/version.map
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
global: MESA*runtime_log*;GIT_VERSION_*;
|
||||||
|
local: *;
|
||||||
|
};
|
||||||
28
zlog/CMakeLists.txt
Normal file
28
zlog/CMakeLists.txt
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
cmake_minimum_required (VERSION 3.5)
|
||||||
|
|
||||||
|
include(ExternalProject)
|
||||||
|
|
||||||
|
ExternalProject_Add(zlog PREFIX zlog
|
||||||
|
URL ${CMAKE_CURRENT_SOURCE_DIR}/zlog-1.2.15.tar.gz
|
||||||
|
URL_MD5 5e79f8d08744c7fef8528dd55a3bcd2d
|
||||||
|
CONFIGURE_COMMAND ""
|
||||||
|
BUILD_COMMAND make
|
||||||
|
INSTALL_COMMAND ""
|
||||||
|
BUILD_IN_SOURCE 1)
|
||||||
|
|
||||||
|
ExternalProject_Get_Property(zlog SOURCE_DIR)
|
||||||
|
file(MAKE_DIRECTORY ${SOURCE_DIR}/src/)
|
||||||
|
|
||||||
|
|
||||||
|
add_library(zlog_static STATIC IMPORTED GLOBAL)
|
||||||
|
add_dependencies(zlog_static zlog)
|
||||||
|
set_property(TARGET zlog_static PROPERTY IMPORTED_LOCATION ${SOURCE_DIR}/src/libzlog.a)
|
||||||
|
set_property(TARGET zlog_static PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${SOURCE_DIR}/src)
|
||||||
|
|
||||||
|
add_library(zlog_shared SHARED IMPORTED GLOBAL)
|
||||||
|
add_dependencies(zlog_shared zlog)
|
||||||
|
set_property(TARGET zlog_shared PROPERTY IMPORTED_LOCATION ${SOURCE_DIR}/src/libzlog.so.1.2)
|
||||||
|
set_property(TARGET zlog_shared PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${SOURCE_DIR}/src)
|
||||||
|
|
||||||
|
install(FILES ${SOURCE_DIR}/src/libzlog.so.1.2 DESTINATION lib COMPONENT LIBRARIES)
|
||||||
|
install(FILES ${SOURCE_DIR}/src/zlog-chk-conf DESTINATION bin COMPONENT EXECUTABLE)
|
||||||
BIN
zlog/zlog-1.2.15.tar.gz
Normal file
BIN
zlog/zlog-1.2.15.tar.gz
Normal file
Binary file not shown.
Reference in New Issue
Block a user