Compare commits
11 Commits
v2.0.2.1-t
...
v2.0.3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0f0e55c877 | ||
|
|
8857f282b9 | ||
|
|
cc0912eed0 | ||
|
|
186571e823 | ||
|
|
e39e641103 | ||
|
|
f461cbbc3d | ||
|
|
05a8eded4b | ||
|
|
92815d2d1f | ||
|
|
ea4185727b | ||
|
|
7066b2b086 | ||
|
|
52db3f0001 |
@@ -14,6 +14,7 @@ stages:
|
||||
- cd $BUILD_PADDING_PREFIX/$CI_PROJECT_PATH
|
||||
- chmod +x ./ci/travis.sh
|
||||
script:
|
||||
- wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
|
||||
- yum makecache fast
|
||||
- ./ci/travis.sh
|
||||
- cd build
|
||||
@@ -91,6 +92,25 @@ release_build_release:
|
||||
except:
|
||||
- /^v[0-9].*-testing$/i
|
||||
|
||||
release_build_release_devel:
|
||||
stage: build
|
||||
variables:
|
||||
BUILD_TYPE: RelWithDebInfo
|
||||
ENABLE_DEVEL_SWITCH: "ON"
|
||||
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
|
||||
except:
|
||||
- /^v[0-9].*-testing$/i
|
||||
|
||||
testing_build_release:
|
||||
stage: build
|
||||
variables:
|
||||
@@ -105,4 +125,21 @@ testing_build_release:
|
||||
paths:
|
||||
- build/*.rpm
|
||||
only:
|
||||
- /^v[0-9].*-testing$/i
|
||||
- /^v[0-9].*-testing$/i
|
||||
|
||||
testing_build_release_devel:
|
||||
stage: build
|
||||
variables:
|
||||
BUILD_TYPE: RelWithDebInfo
|
||||
ENABLE_DEVEL_SWITCH: "ON"
|
||||
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,6 +1,6 @@
|
||||
cmake_minimum_required (VERSION 2.8)
|
||||
|
||||
set(lib_name MESA_handle_logger2)
|
||||
set(lib_name MESA_handle_logger)
|
||||
|
||||
project (${lib_name})
|
||||
|
||||
@@ -62,17 +62,9 @@ install(FILES inc/MESA_handle_logger.h DESTINATION
|
||||
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 \
|
||||
)"
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
add_executable(${lib_name}_demo demo/test_handle_logger.c)
|
||||
target_link_libraries(${lib_name}_demo rt pthread ${lib_name}_static)
|
||||
target_link_libraries(${lib_name}_demo rt pthread ${lib_name}_shared)
|
||||
|
||||
include(Package)
|
||||
|
||||
@@ -38,16 +38,12 @@ set(VERSION_BUILD "${VCS_SHORT_HASH}")
|
||||
# print information
|
||||
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_TAG}-${VCS_DATE}")
|
||||
string(REGEX REPLACE "[-:+/\\.]" "_" GIT_VERSION ${GIT_VERSION})
|
||||
option(DEFINE_GIT_VERSION "Set DEFINE_GIT_VERSION to TRUE or FALSE" TRUE)
|
||||
|
||||
if(DEFINE_GIT_VERSION)
|
||||
add_definitions(-DGIT_VERSION=${GIT_VERSION})
|
||||
option(DEFINE_GIT_VERSION "Set DEFINE_GIT_VERSION to OFF" ON)
|
||||
endif()
|
||||
set(GIT_VERSION
|
||||
"${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})
|
||||
endif()
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
#include "MESA_handle_logger.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <pthread.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
void *sample_handle = NULL;
|
||||
@@ -12,6 +13,7 @@ void *test_handle = NULL;
|
||||
#define LOG_NUM 100000
|
||||
#define MAX_THREAD_NUM 65535
|
||||
|
||||
int g_mode = 0;
|
||||
int g_log_num = 0;
|
||||
int g_thread_num = 0;
|
||||
const char *g_zlog_conf = NULL;
|
||||
@@ -80,7 +82,10 @@ void sig_int_handler(int sig)
|
||||
MESA_destroy_runtime_log_handle(test_handle);
|
||||
sample_handle = NULL;
|
||||
test_handle = NULL;
|
||||
MESA_handle_runtime_log_destruction();
|
||||
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);
|
||||
}
|
||||
@@ -96,24 +101,28 @@ int main(int argc, char ** args)
|
||||
pthread_t t[MAX_THREAD_NUM];
|
||||
int i = 0;
|
||||
|
||||
if(argc != 4)
|
||||
if (argc != 5)
|
||||
{
|
||||
printf("Usage: ./($app) $zlog_conf_path $thread_num $log_num \n");
|
||||
printf("Usage: ./($app) $mode[1 or 2] $zlog_conf_path $thread_num $log_num \n");
|
||||
return -1;
|
||||
}
|
||||
g_zlog_conf = args[1];
|
||||
g_thread_num = atoi(args[2]);
|
||||
g_log_num = atoi(args[3]);
|
||||
g_mode = atoi(args[1]);
|
||||
g_zlog_conf = args[2];
|
||||
g_thread_num = atoi(args[3]);
|
||||
g_log_num = atoi(args[4]);
|
||||
|
||||
if(g_thread_num <= 0 || g_log_num <= 0)
|
||||
{
|
||||
printf("Error, wrong parameter!\n");
|
||||
return -1;
|
||||
}
|
||||
if(0 != MESA_handle_runtime_log_creation(g_zlog_conf))
|
||||
if (g_mode == 2)
|
||||
{
|
||||
printf("MESA_handle_runtime_log_creation return error\n");
|
||||
return -1;
|
||||
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)
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <time.h>
|
||||
|
||||
#define MAX_HANDLE_LOG_PATH 4096
|
||||
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] = "";
|
||||
@@ -116,9 +117,19 @@ static void escape_for_zlog(char *in_buf, int buflen)
|
||||
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];
|
||||
char zlog_rule_conf_content[MAX_HANDLE_LOG_PATH + 1] = "";
|
||||
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)
|
||||
{
|
||||
char temp_filename[1024] = "";
|
||||
@@ -132,16 +143,21 @@ static void snapshot_handle_info(const char *handle_name, const char *log_path,
|
||||
{
|
||||
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));
|
||||
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.%d \"%s.%%d(%%F)\"",
|
||||
handle_name, level, log_path);
|
||||
"\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)
|
||||
{
|
||||
printf("[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;
|
||||
}
|
||||
|
||||
@@ -170,10 +186,11 @@ void *MESA_create_runtime_log_handle(const char *file_path, int level)
|
||||
return NULL;
|
||||
|
||||
snapshot_handle_info(p_name, file_path, level);
|
||||
zlog_reload(NULL);
|
||||
zc = zlog_get_category(p_name);
|
||||
if (!zc)
|
||||
{
|
||||
printf("get zlog category %s in %s fail\n", p_name, tmp_conf_filepath);
|
||||
printf("[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);
|
||||
strncpy(p_handle->runtime_log_file, file_path, sizeof(p_handle->runtime_log_file) - 1);
|
||||
@@ -213,33 +230,59 @@ void MESA_handle_runtime_log(void *handle, int level, const char *module, const
|
||||
|
||||
int MESA_handle_runtime_log_creation(const char *conf_path)
|
||||
{
|
||||
if(conf_path == NULL)
|
||||
char *env = getenv("ZLOG_CONF_PATH");
|
||||
int rc = 0;
|
||||
if (conf_path == NULL || (access(conf_path, R_OK) != 0))
|
||||
{
|
||||
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);
|
||||
printf("[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)
|
||||
{
|
||||
printf("init zlog by %s failed\n", conf_path);
|
||||
printf("[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)
|
||||
{
|
||||
printf("[MESA_handle_runtime_log_creation], INIT zlog by (%s) failed , using [NULL] retry !\n", conf_path);
|
||||
rc = zlog_init(NULL);
|
||||
if (rc)
|
||||
{
|
||||
printf("[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);
|
||||
zlog_profile();
|
||||
}
|
||||
return rc;
|
||||
|
||||
}
|
||||
return -1;
|
||||
printf("[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);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{
|
||||
global: MESA*runtime_log*;
|
||||
global: MESA*runtime_log*;GIT_VERSION_*;
|
||||
local: *;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -4,7 +4,7 @@ include(ExternalProject)
|
||||
|
||||
ExternalProject_Add(zlog PREFIX zlog
|
||||
URL ${CMAKE_CURRENT_SOURCE_DIR}/zlog-1.2.15.tar.gz
|
||||
URL_MD5 155f841543f947bf21112ae4328e7152
|
||||
URL_MD5 5e79f8d08744c7fef8528dd55a3bcd2d
|
||||
CONFIGURE_COMMAND ""
|
||||
BUILD_COMMAND make
|
||||
INSTALL_COMMAND ""
|
||||
@@ -25,4 +25,4 @@ set_property(TARGET zlog_shared PROPERTY IMPORTED_LOCATION ${SOURCE_DIR}/src/li
|
||||
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)
|
||||
install(FILES ${SOURCE_DIR}/src/zlog-chk-conf DESTINATION bin COMPONENT EXECUTABLE)
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user