initialize

This commit is contained in:
崔一鸣
2018-08-12 19:11:04 +08:00
parent 17e2e2050a
commit a76c0d285f
16 changed files with 8627 additions and 0 deletions

19
sample/Makefile Normal file
View File

@@ -0,0 +1,19 @@
#opt: OPTFLAGS = -O2
#export OPTFLAGS
.PHONY: all clean opt
all:
cd new && $(MAKE)
cd old && $(MAKE)
install:
cd new && $(MAKE) install
cd old && $(MAKE) install
clean:
cd new && $(MAKE) clean
cd old && $(MAKE) clean
opt:
$(MAKE) all

22
sample/new/Makefile Normal file
View File

@@ -0,0 +1,22 @@
CC = gcc
TARGET = test_handle_logger
CFLAGS = -g -Wall -fPIC
LIB = -L../../lib/
LIB += -lMESA_handle_logger -lpthread
INCLUDES = -I../../include/
SOURCES = $(wildcard *.c)
OBJECTS = $(SOURCES:.c=.o)
DEPS = $(SOURCES:.c=.d)
.PHONY : clean all install
all : $(TARGET)
$(TARGET) : $(OBJECTS)
$(CC) $(CFLAGS) -o $(TARGET) $(LIB) $(OBJECTS)
%.o : %.c
$(CC) $(CFLAGS) -c $< -o $@
%.d : %.c
$(CC) $< -MM $(INCLUDES) > $@
-include $(DEPS)
clean :
-rm $(TARGET) $(OBJECTS) $(DEPS)

49
sample/new/sample.conf Normal file
View File

@@ -0,0 +1,49 @@
## Do not modify
* GLOBAL:
FORMAT = "[%level|%datetime{%Y-%M-%d %H:%M:%s}]: %msg"
FILENAME = "myeasylog.log"
ENABLED = true
TO_FILE = true
TO_STANDARD_OUTPUT = true
## Specifies subsecond precision (previously called 'milliseconds width'). Width can be within range (1-6)
## SUBSECOND_PRECISION = 6
## PERFORMANCE_TRACKING = true
## If log file size of corresponding level is >= specified size, log file will be truncated.
## MAX_LOG_FILE_SIZE = 2097152
## Specifies number of log entries to hold until we flush pending log data
## LOG_FLUSH_THRESHOLD = 100
## Do not modify
* FATAL:
FORMAT = "[%level|%datetime{%Y-%M-%d %H:%m:%s}]: %msg"
FILENAME = "./log1/fatal_log_%datetime{%Y-%M-%d}"
ENABLED = true
TO_FILE = true
TO_STANDARD_OUTPUT = true
##SUBSECOND_PRECISION = 6
##PERFORMANCE_TRACKING = true
##MAX_LOG_FILE_SIZE = 2097152 ## 2MB
##LOG_FLUSH_THRESHOLD = 100 ## Flush after every 100 logs
* INFO:
FORMAT = "[%level|%datetime{%Y-%M-%d %H:%m:%s}]: %msg"
FILENAME = "./log1/info_log_%datetime{%Y-%M-%d}"
ENABLED = true
TO_FILE = true
TO_STANDARD_OUTPUT = false
##SUBSECOND_PRECISION = 6
##PERFORMANCE_TRACKING = true
##MAX_LOG_FILE_SIZE = 2097152 ## 2MB
##LOG_FLUSH_THRESHOLD = 100 ## Flush after every 100 logs
* DEBUG:
FORMAT = "[%level|%datetime{%Y-%M-%d %H:%m:%s}]: %msg"
FILENAME = "./log1/debug_log_%datetime{%Y-%M-%d}"
ENABLED = true
TO_FILE = true
TO_STANDARD_OUTPUT = false
##SUBSECOND_PRECISION = 6
##PERFORMANCE_TRACKING = true
##MAX_LOG_FILE_SIZE = 2097152 ## 2MB - Comment starts with two hashes (##)
##LOG_FLUSH_THRESHOLD = 100 ## Flush after every 100 logs

View File

@@ -0,0 +1,60 @@
#include "../../include/MESA_handle_logger.h"
#define MAX_LOG_NUM 10
int test_default_conf(){
void* handle = MESA_create_runtime_log_handle_new("logger_id1");
int i = 0;
for(i = 0; i<MAX_LOG_NUM; i++){
MESA_handle_runtime_log(handle, RLOG_LV_DEBUG, "test_default_conf", "test debug log:%s", "xxxxx");
MESA_handle_runtime_log(handle, RLOG_LV_INFO, "test_default_conf", "test info log:%s", "xxxxx");
MESA_handle_runtime_log(handle, RLOG_LV_FATAL, "test_default_conf", "test fatal log:%s", "xxxxx");
}
MESA_destroy_runtime_log_handle(handle);
return 0;
}
int test_read_conf(){
void* handle = MESA_create_runtime_log_handle_new("logger_id1");
int rtn = MESA_read_runtime_log_handle_conf(handle, "./sample.conf");
if(rtn == -1){
return -1;
}
int i = 0;
for(i = 0; i<MAX_LOG_NUM; i++){
MESA_handle_runtime_log(handle, RLOG_LV_DEBUG, "test_read_conf", "test debug log:%s", "xxxxx");
MESA_handle_runtime_log(handle, RLOG_LV_INFO, "test_read_conf", "test info log:%s", "xxxxx");
MESA_handle_runtime_log(handle, RLOG_LV_FATAL, "test_read_conf", "test fatal log:%s", "xxxxx");
}
MESA_destroy_runtime_log_handle(handle);
return 0;
}
int test_set_opt(){
void* handle = MESA_create_runtime_log_handle_new("logger_id2");
MESA_set_runtime_log_handle_opt(handle, RLOG_LV_DEBUG, "enabled", "true");
MESA_set_runtime_log_handle_opt(handle, RLOG_LV_DEBUG, "to_file", "true");
MESA_set_runtime_log_handle_opt(handle, RLOG_LV_DEBUG, "to_standard_output", "true");
MESA_set_runtime_log_handle_opt(handle, RLOG_LV_DEBUG, "format", "[%level|%datetime{%Y-%M-%d %H:%m:%s}]: %msg");
MESA_set_runtime_log_handle_opt(handle, RLOG_LV_DEBUG, "file_name", "./log2/debug_log_%datetime{%Y-%M-%d}");
MESA_set_runtime_log_handle_opt(handle, RLOG_LV_INFO, "file_name", "./log2/info_log_%datetime{%Y-%M-%d}");
MESA_set_runtime_log_handle_opt(handle, RLOG_LV_FATAL, "file_name", "./log2/fatal_log_%datetime{%Y-%M-%d}");
//MESA_set_runtime_log_handle_opt(handle, RLOG_LV_DEBUG, "sub_second_precision", "6");
//MESA_set_runtime_log_handle_opt(handle, RLOG_LV_DEBUG, "performance_tracking", "true");
//MESA_set_runtime_log_handle_opt(handle, RLOG_LV_DEBUG, "max_log_file_size", "2097152");
//MESA_set_runtime_log_handle_opt(handle, RLOG_LV_DEBUG, "log_flush_threshold", "100");
int i = 0;
for(i = 0; i<MAX_LOG_NUM; i++){
MESA_handle_runtime_log(handle, RLOG_LV_DEBUG, "test_set_opt", "test debug log:%s", "xxxxx");
MESA_handle_runtime_log(handle, RLOG_LV_INFO, "test_set_opt", "test info log:%s", "xxxxx");
MESA_handle_runtime_log(handle, RLOG_LV_FATAL, "test_set_opt", "test fatal log:%s", "xxxxx");
}
MESA_destroy_runtime_log_handle(handle);
return 0;
}
int main(int argc, char* argv[]) {
test_default_conf();
test_read_conf();
test_set_opt();
return 0;
}

22
sample/old/Makefile Normal file
View File

@@ -0,0 +1,22 @@
CC = gcc
TARGET = test_handle_logger
CFLAGS = -g -Wall -fPIC
LIB = -L../../lib/
LIB += -lMESA_handle_logger -lpthread
INCLUDES = -I../../include/
SOURCES = $(wildcard *.c)
OBJECTS = $(SOURCES:.c=.o)
DEPS = $(SOURCES:.c=.d)
.PHONY : clean all install
all : $(TARGET)
$(TARGET) : $(OBJECTS)
$(CC) $(CFLAGS) -o $(TARGET) $(LIB) $(OBJECTS)
%.o : %.c
$(CC) $(CFLAGS) -c $< -o $@
%.d : %.c
$(CC) $< -MM $(INCLUDES) > $@
-include $(DEPS)
clean :
-rm $(TARGET) $(OBJECTS) $(DEPS)

49
sample/old/sample.conf Normal file
View File

@@ -0,0 +1,49 @@
## Do not modify
* GLOBAL:
FORMAT = "[%level|%datetime{%Y-%M-%d %H:%M:%s}]: %msg"
FILENAME = "myeasylog.log"
ENABLED = true
TO_FILE = true
TO_STANDARD_OUTPUT = true
## Specifies subsecond precision (previously called 'milliseconds width'). Width can be within range (1-6)
## SUBSECOND_PRECISION = 6
## PERFORMANCE_TRACKING = true
## If log file size of corresponding level is >= specified size, log file will be truncated.
## MAX_LOG_FILE_SIZE = 2097152
## Specifies number of log entries to hold until we flush pending log data
## LOG_FLUSH_THRESHOLD = 100
## Do not modify
* FATAL:
FORMAT = "[%level|%datetime{%Y-%M-%d %H:%m:%s}]: %msg"
FILENAME = "./log1/fatal_log_%datetime{%Y-%M-%d}"
ENABLED = true
TO_FILE = true
TO_STANDARD_OUTPUT = true
##SUBSECOND_PRECISION = 6
##PERFORMANCE_TRACKING = true
##MAX_LOG_FILE_SIZE = 2097152 ## 2MB
##LOG_FLUSH_THRESHOLD = 100 ## Flush after every 100 logs
* INFO:
FORMAT = "[%level|%datetime{%Y-%M-%d %H:%m:%s}]: %msg"
FILENAME = "./log1/info_log_%datetime{%Y-%M-%d}"
ENABLED = true
TO_FILE = true
TO_STANDARD_OUTPUT = false
##SUBSECOND_PRECISION = 6
##PERFORMANCE_TRACKING = true
##MAX_LOG_FILE_SIZE = 2097152 ## 2MB
##LOG_FLUSH_THRESHOLD = 100 ## Flush after every 100 logs
* DEBUG:
FORMAT = "[%level|%datetime{%Y-%M-%d %H:%m:%s}]: %msg"
FILENAME = "./log1/debug_log_%datetime{%Y-%M-%d}"
ENABLED = true
TO_FILE = true
TO_STANDARD_OUTPUT = false
##SUBSECOND_PRECISION = 6
##PERFORMANCE_TRACKING = true
##MAX_LOG_FILE_SIZE = 2097152 ## 2MB - Comment starts with two hashes (##)
##LOG_FLUSH_THRESHOLD = 100 ## Flush after every 100 logs

View File

@@ -0,0 +1,81 @@
#include "../../include/MESA_handle_logger.h"
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <signal.h>
void *sample_handle = NULL;
void *test_handle = NULL;
#define LOG_NUM 100
#define THREAD_NUM 100
void call_logger(int log_num, int thread_num)
{
int i = 0;
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);
//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(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);
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_DEBUG, "test", "test_handle RUNTIEM_LOG test, i = %d, thread_num = %d", i, thread_num);
}
return;
}
void *thread_logger(void *arg)
{
int thread_num = (int)(unsigned long long)arg;
printf("thread %d created! \n", thread_num);
call_logger(LOG_NUM, thread_num);
printf("thread %d finished! \n", thread_num);
return NULL;
}
void sig_handler(int sig)
{
printf("ctrl+c recviced!\n");
MESA_destroy_runtime_log_handle(sample_handle);
MESA_destroy_runtime_log_handle(test_handle);
sample_handle = NULL;
test_handle = NULL;
exit(0);
}
int main()
{
pthread_t t[THREAD_NUM];
int i = 0;
sample_handle = MESA_create_runtime_log_handle("./log/sample_log", RLOG_LV_DEBUG);
if(sample_handle == NULL)
{
printf("get log sample_handle error\n");
return -1;
}
test_handle = MESA_create_runtime_log_handle("./log/test_log", RLOG_LV_DEBUG);
if(test_handle == NULL)
{
printf("get log test_handle error\n");
return -1;
}
for(i = 0; i < THREAD_NUM; i++)
{
pthread_create(&t[i], NULL, thread_logger, (void *)(unsigned long)(i));
}
signal(SIGINT, sig_handler);
while(1)
;
//MESA_destroy_runtime_log_handle(sample_handle);
//MESA_destroy_runtime_log_handle(test_handle);
//sample_handle = NULL;
//test_handle = NULL;
return 0;
}