9 Commits

Author SHA1 Message Date
liuxueli
2eef8296f5 修复rpm打包失败的问题 2020-09-07 18:36:24 +08:00
yangwei
524bca2714 同步写日志文件版本,每次写入都fopen和fclose文件 2020-09-07 13:45:15 +08:00
yangwei
7e10ca27d5 增加mutex,解决跨天切换文件时,重复fclose导致double free的bug 2020-08-17 13:52:43 +08:00
liuxueli
bd5f0acc18 按照规范生成devel.rpm 2020-04-10 11:41:11 +08:00
liuxueli
2aed6fd98f 修正rpm包命名规范 2020-04-07 18:46:11 +08:00
liuxueli
64f208f615 隐藏component的后缀 2020-04-07 17:52:06 +08:00
liuxueli
910602d3f8 支持上传yum源 2020-04-07 13:29:54 +08:00
杨威
d7fd259d43 Merge branch 'Feature-using-env-define-flushnum-msgsize' into 'master'
Feature using env define flushnum msgsize

See merge request MESA_framework/MESA_handle_logger!8
2019-09-24 14:03:54 +08:00
杨威
dfd0b4efb7 增加两个环境变量,HLOG_FLUSH_NUM和HLOG_MSG_SIZE,分别用于控制fflush文件的条数和单条log的最大长度,默认值分别为0和4096
如果有调整的需要,可以在进程运行时定义环境变量,作用范围为进程
2019-09-24 14:03:54 +08:00
10 changed files with 304 additions and 120 deletions

4
.gitignore vendored
View File

@@ -11,3 +11,7 @@ build/
core.*
version.txt
demo/test_handle_logger
cmake-build-debug
GPATH
GRTAGS
GTAGS

View File

@@ -1,42 +1,86 @@
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:
- build
#- test
#- package
- release
variables:
ARTIFACTS_JOB: "build"
build:
.build_by_travis:
before_script:
- mkdir -p $BUILD_PADDING_PREFIX/$CI_PROJECT_NAMESPACE/
- 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
script:
- mkdir -p build
- cd build
- cmake .. -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_PREFIX_PATH=$BUILD_PREFIX
- make
- make package
tags:
- share
extends: .build_by_travis
variables:
BUILD_TYPE: "Debug"
BUILD_PREFIX: "/opt/MESA/"
only:
BUILD_TYPE: Debug
except:
- /^develop.*$/i
- /^master.*$/i
- tags
- pushes
- master
branch_build_release:
stage: build
variables:
BUILD_TYPE: RelWithDebInfo
extends: .build_by_travis
except:
- /^develop.*$/i
- /^master.*$/i
- tags
develop_build_debug:
stage: build
extends: .build_by_travis
variables:
BUILD_TYPE: Debug
PACKAGE: 1
artifacts:
name: "$CI_JOB_NAME-$CI_COMMIT_REF_NAME-debug"
name: "MESA_handle_logger-$CI_COMMIT_REF_NAME-debug"
paths:
- ./build/*.rpm
- build/*.rpm
only:
- /^develop.*$/i
- /^master.*$/i
release:
stage: release
tags:
- share
develop_build_release:
stage: build
extends: .build_by_travis
variables:
BUILD_TYPE: RelWithDebInfo
PACKAGE: 1
artifacts:
name: "MESA_handle_logger-$CI_COMMIT_REF_NAME-release"
paths:
- build/*.rpm
only:
- /^develop.*$/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:
- tags
- master
script:
- /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

View File

@@ -7,24 +7,26 @@ project (${lib_name})
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
include(Version)
#SET(CMAKE_C_COMPILER "/usr/bin/g++")
set(CMAKE_MACOSX_RPATH 0)
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -Wall)
set(CMAKE_INSTALL_PREFIX /opt/MESA)
#for ASAN
option(ENABLE_SANITIZE_ADDRESS "Enable AddressSanitizer" FALSE)
option(ENABLE_SANITIZE_THREAD "Enable ThreadSanitizer" FALSE)
set(ASAN_OPTION "OFF" CACHE STRING " set asan type chosen by the user, using OFF as default")
set_property(CACHE ASAN_OPTION PROPERTY STRINGS OFF ADDRESS THREAD)
message(STATUS "ASAN_OPTION='${ASAN_OPTION}'")
if(ENABLE_SANITIZE_ADDRESS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -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_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lasan")
elseif(ENABLE_SANITIZE_THREAD)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -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_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lasan")
if(ASAN_OPTION MATCHES "ADDRESS")
set(CMAKE_C_FLAGS "${CMAKADDRESS} -g -DCMAKE_BUILD_TYPE=Debug -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_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lasan")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lasan")
elseif(ASAN_OPTION MATCHES "THREAD")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -DCMAKE_BUILD_TYPE=Debug -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_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lasan")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lasan")
endif()
# end of for ASAN
@@ -49,10 +51,8 @@ set_target_properties(${lib_name}_static PROPERTIES OUTPUT_NAME ${lib_name})
set(CMAKE_INSTALL_PREFIX /opt/MESA)
install(TARGETS ${lib_name}_shared LIBRARY DESTINATION
${CMAKE_INSTALL_PREFIX}/lib)
install(FILES inc/${lib_name}.h DESTINATION
${CMAKE_INSTALL_PREFIX}/include/MESA COMPONENT devel)
install(TARGETS ${lib_name}_shared LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib COMPONENT LIBRARIES)
install(FILES inc/${lib_name}.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include/MESA COMPONENT HEADER)

48
ci/get-nprocessors.sh Normal file
View 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

View 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
View 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

View File

@@ -1,36 +1,54 @@
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CPACK_PACKAGE_NAME "${lib_name}-debug")
set(MY_RPM_NAME_PREFIX "lib${lib_name}-debug")
else()
set(CPACK_PACKAGE_NAME ${lib_name})
set(MY_RPM_NAME_PREFIX "lib${lib_name}")
endif()
message(STATUS "Package: ${CPACK_PACKAGE_NAME}")
message(STATUS "Package: ${MY_RPM_NAME_PREFIX}")
set(CPACK_PACKAGE_VECDOR "MESA")
set(CPACK_PACKAGE_VERSION_MAJOR "${VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${VERSION_MINOR}")
set(CPACK_PACKAGE_VERSION_PATCH "${VERSION_PATCH}.${VERSION_BUILD}")
set(CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
set(CPACK_RPM_PACKAGE_DEBUG 1)
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)
# RPM Build
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_AUTOREQPROV "no")
set(CPACK_RPM_PACKAGE_RELEASE_DIST on)
set(CPACK_RPM_DEBUGINFO_PACKAGE on)
set(CPACK_RPM_PACKAGE_AUTOREQPROV "yes")
set(CPACK_RPM_PACKAGE_RELEASE_LIBRARY "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_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)
set(CPACK_BUILD_SOURCE_DIRS "${CMAKE_SOURCE_DIR}")
# Must uninstall the debug package before install release package
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CPACK_RPM_PACKAGE_CONFLICTS "${lib_name}-debug")
else()
set(CPACK_RPM_PACKAGE_CONFLICTS ${lib_name})
# set(CPACK_STRIP_FILES TRUE)
endif()
set(CPACK_RPM_PACKAGE_CONFLICTS ${MY_RPM_NAME_PREFIX})
# set(CPACK_STRIP_FILES TRUE)
include(CPack)

View File

@@ -36,13 +36,18 @@ set(VERSION "${VERSION_MAJOR}_${VERSION_MINOR}_${VERSION_PATCH}")
set(VERSION_BUILD "${VCS_SHORT_HASH}")
# 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
"${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})
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()

View File

@@ -39,7 +39,7 @@ void call_logger(int log_num, int thread_num)
{
MESA_handle_runtime_log(sample_handle, RLOG_LV_INFO, "sample", "sample_handle MESA_handle_runtime_log, i = %d, thread_num = %d", i, thread_num);
//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);
////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);

View File

@@ -8,22 +8,17 @@
#include <unistd.h>
#include<sys/stat.h>
#define LOGMSG_MAX_LEN 4096
#define FLUSH_LOG_NUM 4096
typedef struct log_handle_t
{
int runtime_log_level;
int flush_log_count;
FILE *fp;
char runtime_log_file[1200];
char cur_log_file[LOGMSG_MAX_LEN];
} 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_20190218 = 1;
#define GIT_VERSION_CATTER(v) __attribute__((__used__)) const char * GIT_VERSION_##v = NULL
//const int HANDLE_LOGGER_VERSION_20170816 = 1;
#define GIT_VERSION_CATTER(v) __attribute__((__used__)) const char *GIT_VERSION_##v = NULL
#define GIT_VERSION_EXPEND(v) GIT_VERSION_CATTER(v)
#ifdef __cplusplus
@@ -33,9 +28,9 @@ extern "C"
/* VERSION TAG */
#ifdef GIT_VERSION
GIT_VERSION_EXPEND(GIT_VERSION);
GIT_VERSION_EXPEND(GIT_VERSION);
#else
static __attribute__((__used__)) const char * GIT_VERSION_UNKNOWN = NULL;
static __attribute__((__used__)) const char *GIT_VERSION_UNKNOWN = NULL;
#endif
#undef GIT_VERSION_CATTER
#undef GIT_VERSION_EXPEND
@@ -44,6 +39,8 @@ static __attribute__((__used__)) const char * GIT_VERSION_UNKNOWN = NULL;
}
#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"};
@@ -51,6 +48,44 @@ static unsigned char weekday_str[7][4] =
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)
{
if(dir_path == NULL)
@@ -111,7 +146,7 @@ void *MESA_create_runtime_log_handle(const char *file_path, int level)
if(NULL == (fp = fopen(file_path, "w")))
return NULL;
//fclose(fp);
fclose(fp);
//remove(file_path);
p_handle = (log_handle_t *)calloc(sizeof(log_handle_t), 1);
@@ -121,7 +156,6 @@ void *MESA_create_runtime_log_handle(const char *file_path, int level)
strncpy(p_handle->runtime_log_file, file_path, 1024);
p_handle->runtime_log_file[1024] = '\0';
p_handle->runtime_log_level = level;
//p_handle->fp = fp;
return (void *)p_handle;
}
@@ -129,13 +163,7 @@ void MESA_destroy_runtime_log_handle(void *handle)
{
if(handle != NULL)
{
log_handle_t *p_handle = (log_handle_t *)handle;
if (p_handle->fp != NULL)
{
fclose(p_handle->fp);
p_handle->fp = NULL;
}
free(handle);
free(handle);
handle = NULL;
}
@@ -150,7 +178,7 @@ void MESA_handle_runtime_log(void *handle, int level, const char *module, const
va_list ap;
FILE *fp;
struct tm local_time;
char tmp_log_file_name[1400];
char tmp_log_file_name[1201];
log_handle_t *p_handle = (log_handle_t *)handle;
if(p_handle == NULL || p_handle->runtime_log_file == NULL)return;
@@ -159,6 +187,7 @@ void MESA_handle_runtime_log(void *handle, int level, const char *module, const
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);
@@ -205,37 +234,9 @@ void MESA_handle_runtime_log(void *handle, int level, const char *module, const
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(NULL == (fp = fopen(tmp_log_file_name, "a"))) return;
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;
fprintf(fp, "%s", buf);
fclose(fp);
}