Compare commits
24 Commits
dev-1.1
...
v2.0.2-tes
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
332201d4b0 | ||
|
|
ce403b8ca5 | ||
|
|
f15a1fd617 | ||
|
|
d42c5eeb0f | ||
|
|
49b61b11a9 | ||
|
|
bc575233b7 | ||
|
|
b4f239ae9c | ||
|
|
90fb91cd42 | ||
|
|
9c410a1e7e | ||
|
|
8dee487439 | ||
|
|
2e4c2d3098 | ||
|
|
40512a0421 | ||
|
|
ab7f4edda1 | ||
|
|
bafd63face | ||
|
|
e6e1f8494e | ||
|
|
19911a962c | ||
|
|
c21cdcb3f0 | ||
|
|
745f908d70 | ||
|
|
23609f6f02 | ||
|
|
6ae5d5ffa9 | ||
|
|
1f9fc66152 | ||
|
|
635bb180bf | ||
|
|
117720197e | ||
|
|
49822347cb |
5
.gitignore
vendored
5
.gitignore
vendored
@@ -11,3 +11,8 @@ build/
|
|||||||
core.*
|
core.*
|
||||||
version.txt
|
version.txt
|
||||||
demo/test_handle_logger
|
demo/test_handle_logger
|
||||||
|
cmake-build-debug
|
||||||
|
build-*/
|
||||||
|
GPATH
|
||||||
|
GRTAGS
|
||||||
|
GTAGS
|
||||||
|
|||||||
126
.gitlab-ci.yml
126
.gitlab-ci.yml
@@ -1,42 +1,108 @@
|
|||||||
image: "git.mesalab.cn:7443/mesa_framework/framework-build-env:master"
|
image: "git.mesalab.cn:7443/mesa_platform/build-env:master"
|
||||||
|
variables:
|
||||||
|
GIT_STRATEGY: "clone"
|
||||||
|
BUILD_PADDING_PREFIX: /tmp/padding_for_CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX_PREFIX_PREFIX_PREFIX_PREFIX_PREFIX/
|
||||||
|
INSTALL_PREFIX: "/opt/MESA/lib/"
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- build
|
- build
|
||||||
#- test
|
|
||||||
#- package
|
|
||||||
- release
|
|
||||||
|
|
||||||
variables:
|
.build_by_travis:
|
||||||
ARTIFACTS_JOB: "build"
|
before_script:
|
||||||
|
- mkdir -p $BUILD_PADDING_PREFIX/$CI_PROJECT_NAMESPACE/
|
||||||
build:
|
- ln -s $CI_PROJECT_DIR $BUILD_PADDING_PREFIX/$CI_PROJECT_PATH
|
||||||
|
- cd $BUILD_PADDING_PREFIX/$CI_PROJECT_PATH
|
||||||
|
- chmod +x ./ci/travis.sh
|
||||||
|
script:
|
||||||
|
- yum makecache
|
||||||
|
- ./ci/travis.sh
|
||||||
|
- cd build
|
||||||
|
tags:
|
||||||
|
- share
|
||||||
|
|
||||||
|
branch_build_debug:
|
||||||
stage: build
|
stage: build
|
||||||
script:
|
extends: .build_by_travis
|
||||||
- mkdir -p build
|
|
||||||
- cd build
|
|
||||||
- cmake .. -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_PREFIX_PATH=$BUILD_PREFIX
|
|
||||||
- make
|
|
||||||
- make package
|
|
||||||
tags:
|
|
||||||
- share
|
|
||||||
variables:
|
variables:
|
||||||
BUILD_TYPE: "Debug"
|
BUILD_TYPE: Debug
|
||||||
BUILD_PREFIX: "/opt/MESA/"
|
except:
|
||||||
only:
|
- /^dev*.*$/i
|
||||||
|
- /^rel*.*$/i
|
||||||
|
- /^master.*$/i
|
||||||
- tags
|
- tags
|
||||||
- pushes
|
|
||||||
- master
|
|
||||||
|
|
||||||
|
branch_build_release:
|
||||||
|
stage: build
|
||||||
|
variables:
|
||||||
|
BUILD_TYPE: RelWithDebInfo
|
||||||
|
extends: .build_by_travis
|
||||||
|
except:
|
||||||
|
- /^dev*.*$/i
|
||||||
|
- /^rel*.*$/i
|
||||||
|
- /^master.*$/i
|
||||||
|
- tags
|
||||||
|
|
||||||
|
develop_build_debug:
|
||||||
|
stage: build
|
||||||
|
extends: .build_by_travis
|
||||||
|
variables:
|
||||||
|
BUILD_TYPE: Debug
|
||||||
|
PACKAGE: 1
|
||||||
artifacts:
|
artifacts:
|
||||||
name: "$CI_JOB_NAME-$CI_COMMIT_REF_NAME-debug"
|
name: "MESA_handle_logger-$CI_COMMIT_REF_NAME-debug"
|
||||||
paths:
|
paths:
|
||||||
- ./build/*.rpm
|
- build/*.rpm
|
||||||
|
only:
|
||||||
|
- /^dev*.*$/i
|
||||||
|
- /^rel*.*$/i
|
||||||
|
- /^master.*$/i
|
||||||
|
|
||||||
release:
|
develop_build_release:
|
||||||
stage: release
|
stage: build
|
||||||
tags:
|
extends: .build_by_travis
|
||||||
- share
|
variables:
|
||||||
|
BUILD_TYPE: RelWithDebInfo
|
||||||
|
PACKAGE: 1
|
||||||
|
artifacts:
|
||||||
|
name: "MESA_handle_logger-$CI_COMMIT_REF_NAME-release"
|
||||||
|
paths:
|
||||||
|
- build/*.rpm
|
||||||
|
only:
|
||||||
|
- /^dev*.*$/i
|
||||||
|
- /^rel*.*$/i
|
||||||
|
- /^master.*$/i
|
||||||
|
|
||||||
|
|
||||||
|
release_build_release:
|
||||||
|
stage: build
|
||||||
|
variables:
|
||||||
|
BUILD_TYPE: RelWithDebInfo
|
||||||
|
PACKAGE: 1
|
||||||
|
UPLOAD: 1
|
||||||
|
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:
|
only:
|
||||||
- tags
|
- tags
|
||||||
- master
|
except:
|
||||||
script:
|
- /^v[0-9].*-testing$/i
|
||||||
- /bin/bash -x ./autorelease.sh $CI_API_V4_URL $CI_PROJECT_URL $CI_PROJECT_ID $CI_TOKEN $CI_COMMIT_TAG $ARTIFACTS_JOB $CI_PROJECT_NAME
|
|
||||||
|
testing_build_release:
|
||||||
|
stage: build
|
||||||
|
variables:
|
||||||
|
BUILD_TYPE: RelWithDebInfo
|
||||||
|
PACKAGE: 1
|
||||||
|
UPLOAD: 1
|
||||||
|
PULP3_REPO_NAME: framework-testing-x86_64.el7
|
||||||
|
PULP3_DIST_NAME: framework-testing-x86_64.el7
|
||||||
|
extends: .build_by_travis
|
||||||
|
artifacts:
|
||||||
|
name: "MESA_handle_logger-$CI_COMMIT_REF_NAME-release"
|
||||||
|
paths:
|
||||||
|
- build/*.rpm
|
||||||
|
only:
|
||||||
|
- /^v[0-9].*-testing$/i
|
||||||
@@ -1,9 +1,12 @@
|
|||||||
cmake_minimum_required (VERSION 2.8)
|
cmake_minimum_required (VERSION 2.8)
|
||||||
|
|
||||||
set(lib_name MESA_handle_logger)
|
set(lib_name MESA_handle_logger2)
|
||||||
|
|
||||||
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)
|
||||||
|
|
||||||
@@ -30,38 +33,46 @@ endif()
|
|||||||
|
|
||||||
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_shared)
|
||||||
|
set_target_properties(${lib_name}_shared PROPERTIES LINK_FLAGS
|
||||||
|
"-Wl,--version-script=${PROJECT_SOURCE_DIR}/src/version.map")
|
||||||
|
|
||||||
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_shared)
|
||||||
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
|
install(FILES inc/MESA_handle_logger.h DESTINATION
|
||||||
${CMAKE_INSTALL_PREFIX}/lib)
|
|
||||||
install(FILES inc/${lib_name}.h DESTINATION
|
|
||||||
${CMAKE_INSTALL_PREFIX}/include/MESA COMPONENT devel)
|
${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(CODE "execute_process( \
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E create_symlink \
|
||||||
|
libMESA_handle_logger2.so \
|
||||||
|
${CMAKE_INSTALL_PREFIX}/lib/libMESA_handle_logger.so \
|
||||||
|
)"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
file(GLOB DEMO
|
add_executable(${lib_name}_demo demo/test_handle_logger.c)
|
||||||
"demo/*.c"
|
|
||||||
"demo/*.cpp"
|
|
||||||
)
|
|
||||||
|
|
||||||
add_executable(${lib_name}_demo ${DEMO})
|
|
||||||
target_link_libraries(${lib_name}_demo rt pthread ${lib_name}_static)
|
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;
|
||||||
|
|||||||
48
ci/get-nprocessors.sh
Normal file
48
ci/get-nprocessors.sh
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Copyright 2017 Google Inc.
|
||||||
|
# All Rights Reserved.
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# Redistribution and use in source and binary forms, with or without
|
||||||
|
# modification, are permitted provided that the following conditions are
|
||||||
|
# met:
|
||||||
|
#
|
||||||
|
# * Redistributions of source code must retain the above copyright
|
||||||
|
# notice, this list of conditions and the following disclaimer.
|
||||||
|
# * Redistributions in binary form must reproduce the above
|
||||||
|
# copyright notice, this list of conditions and the following disclaimer
|
||||||
|
# in the documentation and/or other materials provided with the
|
||||||
|
# distribution.
|
||||||
|
# * Neither the name of Google Inc. nor the names of its
|
||||||
|
# contributors may be used to endorse or promote products derived from
|
||||||
|
# this software without specific prior written permission.
|
||||||
|
#
|
||||||
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
# This file is typically sourced by another script.
|
||||||
|
# if possible, ask for the precise number of processors,
|
||||||
|
# otherwise take 2 processors as reasonable default; see
|
||||||
|
# https://docs.travis-ci.com/user/speeding-up-the-build/#Makefile-optimization
|
||||||
|
if [ -x /usr/bin/getconf ]; then
|
||||||
|
NPROCESSORS=$(/usr/bin/getconf _NPROCESSORS_ONLN)
|
||||||
|
else
|
||||||
|
NPROCESSORS=2
|
||||||
|
fi
|
||||||
|
|
||||||
|
# as of 2017-09-04 Travis CI reports 32 processors, but GCC build
|
||||||
|
# crashes if parallelized too much (maybe memory consumption problem),
|
||||||
|
# so limit to 4 processors for the time being.
|
||||||
|
if [ $NPROCESSORS -gt 4 ] ; then
|
||||||
|
echo "$0:Note: Limiting processors to use by make from $NPROCESSORS to 4."
|
||||||
|
NPROCESSORS=4
|
||||||
|
fi
|
||||||
3
ci/perpare_pulp3_netrc.sh
Normal file
3
ci/perpare_pulp3_netrc.sh
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
#!/usr/bin/env sh
|
||||||
|
set -evx
|
||||||
|
echo "machine ${PULP3_SERVER_URL}\nlogin ${PULP3_SERVER_LOGIN}\npassword ${PULP3_SERVER_PASSWORD}\n" > ~/.netrc
|
||||||
61
ci/travis.sh
Normal file
61
ci/travis.sh
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
#!/usr/bin/env sh
|
||||||
|
set -evx
|
||||||
|
|
||||||
|
chmod +x ci/get-nprocessors.sh
|
||||||
|
. ci/get-nprocessors.sh
|
||||||
|
|
||||||
|
# if possible, ask for the precise number of processors,
|
||||||
|
# otherwise take 2 processors as reasonable default; see
|
||||||
|
# https://docs.travis-ci.com/user/speeding-up-the-build/#Makefile-optimization
|
||||||
|
if [ -x /usr/bin/getconf ]; then
|
||||||
|
NPROCESSORS=$(/usr/bin/getconf _NPROCESSORS_ONLN)
|
||||||
|
else
|
||||||
|
NPROCESSORS=2
|
||||||
|
fi
|
||||||
|
|
||||||
|
# as of 2017-09-04 Travis CI reports 32 processors, but GCC build
|
||||||
|
# crashes if parallelized too much (maybe memory consumption problem),
|
||||||
|
# so limit to 4 processors for the time being.
|
||||||
|
if [ $NPROCESSORS -gt 4 ] ; then
|
||||||
|
echo "$0:Note: Limiting processors to use by make from $NPROCESSORS to 4."
|
||||||
|
NPROCESSORS=4
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Tell make to use the processors. No preceding '-' required.
|
||||||
|
MAKEFLAGS="j${NPROCESSORS}"
|
||||||
|
export MAKEFLAGS
|
||||||
|
|
||||||
|
env | sort
|
||||||
|
|
||||||
|
# Set default values to OFF for these variables if not specified.
|
||||||
|
: "${NO_EXCEPTION:=OFF}"
|
||||||
|
: "${NO_RTTI:=OFF}"
|
||||||
|
: "${COMPILER_IS_GNUCXX:=OFF}"
|
||||||
|
|
||||||
|
# Install dependency from YUM
|
||||||
|
#yum install -y mrzcpd framework numactl-devel zlib-devel librdkafka-devel systemd-devel
|
||||||
|
mkdir build || true
|
||||||
|
cd build
|
||||||
|
|
||||||
|
cmake3 -DCMAKE_CXX_FLAGS=$CXX_FLAGS \
|
||||||
|
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
|
||||||
|
-DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX \
|
||||||
|
-DENABLE_DEVEL=$ENABLE_DEVEL_SWITCH \
|
||||||
|
..
|
||||||
|
|
||||||
|
make
|
||||||
|
|
||||||
|
if [ -n "${PACKAGE}" ]; then
|
||||||
|
make package
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "${UPLOAD}" ]; then
|
||||||
|
cp ~/rpm_upload_tools.py ./
|
||||||
|
python3 rpm_upload_tools.py ${PULP3_REPO_NAME} ${PULP3_DIST_NAME} *.rpm
|
||||||
|
fi
|
||||||
|
|
||||||
|
#if [ -n "${UPLOAD_SYMBOL_FILES}" ]; then
|
||||||
|
# rpm -i tfe*debuginfo*.rpm
|
||||||
|
# cp /usr/lib/debug/opt/tsg/tfe/bin/tfe.debug /tmp/tfe.debuginfo.${CI_COMMIT_SHORT_SHA}
|
||||||
|
# sentry-cli upload-dif -t elf /tmp/tfe.debuginfo.${CI_COMMIT_SHORT_SHA}
|
||||||
|
#fi
|
||||||
@@ -1,36 +1,57 @@
|
|||||||
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||||
set(CPACK_PACKAGE_NAME "${lib_name}-debug")
|
set(MY_RPM_NAME_PREFIX "lib${lib_name}-debug")
|
||||||
else()
|
else()
|
||||||
set(CPACK_PACKAGE_NAME ${lib_name})
|
set(MY_RPM_NAME_PREFIX "lib${lib_name}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
message(STATUS "Package: ${CPACK_PACKAGE_NAME}")
|
message(STATUS "Package: ${MY_RPM_NAME_PREFIX}")
|
||||||
|
|
||||||
set(CPACK_PACKAGE_VECDOR "MESA")
|
set(CPACK_PACKAGE_VECDOR "MESA")
|
||||||
set(CPACK_PACKAGE_VERSION_MAJOR "${VERSION_MAJOR}")
|
set(CPACK_PACKAGE_VERSION_MAJOR "${VERSION_MAJOR}")
|
||||||
set(CPACK_PACKAGE_VERSION_MINOR "${VERSION_MINOR}")
|
set(CPACK_PACKAGE_VERSION_MINOR "${VERSION_MINOR}")
|
||||||
set(CPACK_PACKAGE_VERSION_PATCH "${VERSION_PATCH}.${VERSION_BUILD}")
|
set(CPACK_PACKAGE_VERSION_PATCH "${VERSION_PATCH}.${VERSION_BUILD}")
|
||||||
set(CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
|
set(CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
|
||||||
|
set(CPACK_PACKAGE_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}.${VERSION_BUILD}")
|
||||||
set(CPACK_RPM_PACKAGE_DEBUG 1)
|
execute_process(COMMAND bash -c "echo -ne \"`uname -r | awk -F'.' '{print $5\".\"$6\".\"$7}'`\"" OUTPUT_VARIABLE SYSTEM_VERSION)
|
||||||
|
|
||||||
# RPM Build
|
# RPM Build
|
||||||
set(CPACK_GENERATOR "RPM")
|
set(CPACK_GENERATOR "RPM")
|
||||||
set(CPACK_RPM_AUTO_GENERATED_FILE_NAME ON)
|
|
||||||
set(CPACK_RPM_FILE_NAME "RPM-DEFAULT")
|
|
||||||
set(CPACK_RPM_PACKAGE_VENDOR "MESA")
|
set(CPACK_RPM_PACKAGE_VENDOR "MESA")
|
||||||
set(CPACK_RPM_PACKAGE_AUTOREQPROV "no")
|
set(CPACK_RPM_PACKAGE_AUTOREQPROV "yes")
|
||||||
set(CPACK_RPM_PACKAGE_RELEASE_DIST on)
|
set(CPACK_RPM_PACKAGE_RELEASE_LIBRARY "on")
|
||||||
set(CPACK_RPM_DEBUGINFO_PACKAGE on)
|
set(CPACK_RPM_DEBUGINFO_PACKAGE "on")
|
||||||
|
set(CPACK_RPM_PACKAGE_DEBUG 1)
|
||||||
|
|
||||||
|
set(CPACK_RPM_COMPONENT_INSTALL ON)
|
||||||
|
set(CPACK_COMPONENTS_IGNORE_GROUPS 1)
|
||||||
|
set(CPACK_COMPONENTS_GROUPING ONE_PER_GROUP)
|
||||||
|
set(CPACK_COMPONENT_HEADER_DISPLAY_NAME "develop")
|
||||||
|
set(CPACK_COMPONENT_LIBRARIES_REQUIRED TRUE)
|
||||||
|
set(CPACK_COMPONENT_HEADER_REQUIRED TRUE)
|
||||||
|
set(CPACK_RPM_HEADER_PACKAGE_NAME "${MY_RPM_NAME_PREFIX}-devel")
|
||||||
|
set(CPACK_RPM_LIBRARIES_PACKAGE_NAME ${MY_RPM_NAME_PREFIX})
|
||||||
|
|
||||||
|
set(CPACK_RPM_FILE_NAME "${CPACK_RPM_LIBRARIES_PACKAGE_NAME}-${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_LIBRARIES_GROUP "libraries")
|
||||||
|
set(CPACK_COMPONENT_EXECUTABLE_GROUP "libraries")
|
||||||
|
|
||||||
|
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_COMPONENT_HEADER_GROUP "header")
|
||||||
|
|
||||||
|
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_COMPONENTS_ALL LIBRARIES HEADER EXECUTABLE)
|
||||||
|
|
||||||
|
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}")
|
||||||
|
|
||||||
# Must uninstall the debug package before install release package
|
# Must uninstall the debug package before install release package
|
||||||
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
set(CPACK_RPM_PACKAGE_CONFLICTS ${MY_RPM_NAME_PREFIX})
|
||||||
set(CPACK_RPM_PACKAGE_CONFLICTS "${lib_name}-debug")
|
|
||||||
else()
|
|
||||||
set(CPACK_RPM_PACKAGE_CONFLICTS ${lib_name})
|
|
||||||
# set(CPACK_STRIP_FILES TRUE)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
|
# set(CPACK_STRIP_FILES TRUE)
|
||||||
include(CPack)
|
include(CPack)
|
||||||
|
|||||||
2
cmake/PostInstall.in
Normal file
2
cmake/PostInstall.in
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
ldconfig
|
||||||
@@ -36,13 +36,18 @@ set(VERSION "${VERSION_MAJOR}_${VERSION_MINOR}_${VERSION_PATCH}")
|
|||||||
set(VERSION_BUILD "${VCS_SHORT_HASH}")
|
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 OFF" OFF)
|
||||||
|
|
||||||
set(GIT_VERSION
|
set(GIT_VERSION
|
||||||
"${VERSION}-${CMAKE_BUILD_TYPE}-${VERSION_BUILD}-${VCS_BRANCH}-${VCS_DATE}")
|
"${VERSION}-${CMAKE_BUILD_TYPE}-${VERSION_BUILD}-${VCS_BRANCH}-${VCS_TAG}-${VCS_DATE}")
|
||||||
|
|
||||||
string(REGEX REPLACE "[-:+/\\.]" "_" GIT_VERSION ${GIT_VERSION})
|
string(REGEX REPLACE "[-:+/\\.]" "_" GIT_VERSION ${GIT_VERSION})
|
||||||
|
|
||||||
add_definitions(-DGIT_VERSION=${GIT_VERSION})
|
if(DEFINE_GIT_VERSION)
|
||||||
|
add_definitions(-DGIT_VERSION=${GIT_VERSION})
|
||||||
|
option(DEFINE_GIT_VERSION "Set DEFINE_GIT_VERSION to OFF" ON)
|
||||||
|
endif()
|
||||||
|
|
||||||
message(STATUS "add GIT_VERSION: ${GIT_VERSION}")
|
endif()
|
||||||
|
|||||||
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
|
||||||
@@ -14,6 +14,7 @@ void *test_handle = NULL;
|
|||||||
|
|
||||||
int g_log_num = 0;
|
int g_log_num = 0;
|
||||||
int g_thread_num = 0;
|
int g_thread_num = 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;
|
||||||
|
|
||||||
@@ -37,11 +38,11 @@ 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);
|
MESA_handle_runtime_log(sample_handle, RLOG_LV_DEBUG, "sample", "sample_handle MESA_handle_runtime_log, i = %d, thread_num = %d", i, thread_num);
|
||||||
//sleep(1);
|
//sleep(1);
|
||||||
//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);
|
//MESA_HANDLE_RUNTIME_LOG(sample_handle, RLOG_LV_FATAL, "sample", "sample_handle RUNTIEM_LOG test, i = %d, thread_num = %d", i, thread_num);
|
||||||
////sleep(1);
|
//sleep(1);
|
||||||
//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(test_handle, RLOG_LV_FATAL, "test", "test_handle RUNTIEM_LOG test, i = %d, thread_num = %d", i, thread_num);
|
||||||
}
|
}
|
||||||
clock_gettime(CLOCK_MONOTONIC, &end);
|
clock_gettime(CLOCK_MONOTONIC, &end);
|
||||||
@@ -72,36 +73,49 @@ void *thread_logger(void *arg)
|
|||||||
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);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
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 != 4)
|
||||||
{
|
{
|
||||||
printf("Usage: ./($app) $thread_num $log_num \n");
|
printf("Usage: ./($app) $zlog_conf_path $thread_num $log_num \n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
g_thread_num = atoi(args[1]);
|
g_zlog_conf = args[1];
|
||||||
g_log_num = atoi(args[2]);
|
g_thread_num = atoi(args[2]);
|
||||||
|
g_log_num = atoi(args[3]);
|
||||||
|
|
||||||
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(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 +133,8 @@ 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);
|
||||||
while(1)
|
while(1)
|
||||||
;
|
;
|
||||||
//MESA_destroy_runtime_log_handle(sample_handle);
|
//MESA_destroy_runtime_log_handle(sample_handle);
|
||||||
|
|||||||
@@ -19,11 +19,15 @@ extern "C"
|
|||||||
#define RLOG_LV_FATAL 30
|
#define RLOG_LV_FATAL 30
|
||||||
|
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 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 +37,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
|
||||||
|
|||||||
@@ -1,22 +1,24 @@
|
|||||||
#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
|
||||||
|
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] = "";
|
||||||
|
|
||||||
#define LOGMSG_MAX_LEN 4096
|
|
||||||
#define FLUSH_LOG_NUM 4096
|
|
||||||
typedef struct log_handle_t
|
typedef struct log_handle_t
|
||||||
{
|
{
|
||||||
int runtime_log_level;
|
int runtime_log_level;
|
||||||
int flush_log_count;
|
zlog_category_t *zc;
|
||||||
FILE *fp;
|
const char *global_conf_path;
|
||||||
char runtime_log_file[1200];
|
char runtime_log_file[MAX_HANDLE_LOG_PATH];
|
||||||
char cur_log_file[LOGMSG_MAX_LEN];
|
|
||||||
} log_handle_t;
|
} log_handle_t;
|
||||||
|
|
||||||
|
|
||||||
@@ -45,12 +47,6 @@ static __attribute__((__used__)) const char * GIT_VERSION_UNKNOWN = NULL;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
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"};
|
|
||||||
|
|
||||||
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)
|
||||||
@@ -93,35 +89,96 @@ 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 = fileno(fp);
|
||||||
|
int fno = fp;
|
||||||
|
sprintf(proclnk, "/proc/self/fd/%d", fno);
|
||||||
|
int r = readlink(proclnk, buf, buflen);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
static char tmp_template[] = "/tmp/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 void snapshot_handle_info(const char *handle_name, const char *log_path, int level)
|
||||||
|
{
|
||||||
|
char zlog_rule_conf_content[MAX_HANDLE_LOG_PATH + 1];
|
||||||
|
if (g_zlog_conf_fp == -1)
|
||||||
|
{
|
||||||
|
char temp_filename[1024] = "";
|
||||||
|
sprintf(temp_filename, "/tmp/MESA_handle_logger_%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;
|
||||||
|
}
|
||||||
|
int len = snprintf(zlog_rule_conf_content, sizeof(zlog_rule_conf_content),
|
||||||
|
"[global]\ndefault format = \"%%d(%%c), %%V, %F, %U, %%m%%n\" \n[levels]\nDEBUG=10\nINFO=20\nFATAL=30\n[rules]");
|
||||||
|
write(g_zlog_conf_fp, zlog_rule_conf_content, strlen(zlog_rule_conf_content));
|
||||||
|
fsync(g_zlog_conf_fp);
|
||||||
|
}
|
||||||
|
snprintf(zlog_rule_conf_content, sizeof(zlog_rule_conf_content),
|
||||||
|
"\n%s.%d \"%s.%%d(%%F)\"",
|
||||||
|
handle_name, level, log_path);
|
||||||
|
write(g_zlog_conf_fp, zlog_rule_conf_content, strlen(zlog_rule_conf_content));
|
||||||
|
fsync(g_zlog_conf_fp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
|
char handle_name[MAX_HANDLE_LOG_PATH];
|
||||||
|
char *p_path_end = rindex(file_path, '/');
|
||||||
|
|
||||||
|
char *p_name = p_path_end+1;
|
||||||
|
|
||||||
|
strcpy(handle_name, file_path);
|
||||||
|
escape_for_zlog(handle_name, strlen(handle_name));
|
||||||
|
p_name = handle_name;
|
||||||
|
|
||||||
|
|
||||||
//creating file_path failed, return NULL
|
//creating file_path failed, return NULL
|
||||||
char *p_path = rindex(file_path, '/');
|
if (create_path(file_path, p_path_end - file_path) < 0)
|
||||||
if(p_path != 0)
|
return NULL;
|
||||||
{
|
|
||||||
if(create_path(file_path, p_path - file_path) < 0)
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
if(NULL == (fp = fopen(file_path, "w")))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
//fclose(fp);
|
snapshot_handle_info(p_name, file_path, level);
|
||||||
//remove(file_path);
|
zc = zlog_get_category(p_name);
|
||||||
|
if (!zc)
|
||||||
|
{
|
||||||
|
printf("get zlog category %s in %s fail\n", p_name, tmp_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->fp = fp;
|
p_handle->zc = zc;
|
||||||
return (void *)p_handle;
|
return (void *)p_handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,113 +186,99 @@ void MESA_destroy_runtime_log_handle(void *handle)
|
|||||||
{
|
{
|
||||||
if(handle != NULL)
|
if(handle != NULL)
|
||||||
{
|
{
|
||||||
log_handle_t *p_handle = (log_handle_t *)handle;
|
free(handle);
|
||||||
if (p_handle->fp != NULL)
|
|
||||||
{
|
|
||||||
fclose(p_handle->fp);
|
|
||||||
p_handle->fp = NULL;
|
|
||||||
}
|
|
||||||
free(handle);
|
|
||||||
handle = NULL;
|
handle = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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;
|
|
||||||
FILE *fp;
|
|
||||||
struct tm local_time;
|
|
||||||
char tmp_log_file_name[1400];
|
|
||||||
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;
|
|
||||||
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_list ap;
|
||||||
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);
|
||||||
|
return ;
|
||||||
if(0 >= LOGMSG_MAX_LEN - len) 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);
|
|
||||||
|
|
||||||
OPEN_LOG_FILE:
|
|
||||||
if(p_handle->fp == NULL)
|
|
||||||
{
|
|
||||||
if(NULL == (fp = fopen(tmp_log_file_name, "a"))) return;
|
|
||||||
p_handle->fp = fp;
|
|
||||||
p_handle->flush_log_count = 0;
|
|
||||||
memcpy(p_handle->cur_log_file, tmp_log_file_name, strlen(tmp_log_file_name));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (0 != memcmp(tmp_log_file_name, p_handle->cur_log_file, strlen(tmp_log_file_name)))
|
|
||||||
{
|
|
||||||
fclose(p_handle->fp);
|
|
||||||
p_handle->fp = NULL;
|
|
||||||
goto OPEN_LOG_FILE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (0 > fprintf(p_handle->fp, "%s", buf))
|
|
||||||
{
|
|
||||||
fclose(p_handle->fp);
|
|
||||||
p_handle->fp = NULL;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
p_handle->flush_log_count+=1;
|
|
||||||
if (p_handle->flush_log_count >= FLUSH_LOG_NUM)
|
|
||||||
{
|
|
||||||
fflush(p_handle->fp);
|
|
||||||
p_handle->flush_log_count = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int MESA_handle_runtime_log_creation(const char *conf_path)
|
||||||
|
{
|
||||||
|
if(conf_path == NULL)
|
||||||
|
{
|
||||||
|
printf("MESA_handle_runtime_log_creationUsing NULL, will using ZLOG_CONF_PATH or strout as default profile\n");
|
||||||
|
return zlog_init(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (access(conf_path, R_OK) != -1)
|
||||||
|
{
|
||||||
|
|
||||||
|
int rc = zlog_init(conf_path);
|
||||||
|
if (rc)
|
||||||
|
{
|
||||||
|
printf("init zlog by %s failed\n", conf_path);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
strcpy(global_conf_filepath, conf_path);
|
||||||
|
zlog_profile();
|
||||||
|
}
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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*;
|
||||||
|
local: *;
|
||||||
|
};
|
||||||
23
zlog/CMakeLists.txt
Normal file
23
zlog/CMakeLists.txt
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
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 155f841543f947bf21112ae4328e7152
|
||||||
|
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_shared SHARED IMPORTED GLOBAL)
|
||||||
|
add_dependencies(zlog_shared zlog)
|
||||||
|
set_property(TARGET zlog_shared PROPERTY IMPORTED_LOCATION ${SOURCE_DIR}/src/libzlog.so)
|
||||||
|
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(PROGRAMS ${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