Skip to content

Commit

Permalink
代码优化
Browse files Browse the repository at this point in the history
  • Loading branch information
Gavin Chan committed Nov 29, 2016
1 parent b070f6e commit e482258
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 6 deletions.
Binary file modified cmake-build-debug/plog
Binary file not shown.
3 changes: 2 additions & 1 deletion include/libplog.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ typedef enum {


char *get_level(log_level_t level);
int libplog_init (const char *log_path, const char *project_name, const unsigned log_num, const size_t log_size);
int libplog_init (const char *log_path, const char *project_name,
const unsigned log_num, const size_t log_size, const log_level_t print_level);
int libplog_destroy();
int libplog_write (log_level_t level, char *msg);

Expand Down
4 changes: 2 additions & 2 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void log_print(const char *file_name, const char *func_name,
void *
print_log(void *arg)
{
for(int i = 0; i < 100; ++i)
for(int i = 0; i < 1000; ++i)
{
PLOG_ERROR("我是测试字符串 %s,第 %d次打印,我是线程%s\n","张鹏",i, (char *)arg);
PLOG_DEBUG("我是测试字符串 %s,第 %d次打印,我是线程%s\n","灿灿",i, (char *)arg);
Expand All @@ -104,7 +104,7 @@ main()
pthread_t thrd[THRD_COUNT];
char thrdname[20][10]={"thread-A","thread-B","thread-C","thread-D","thread-E","thread-F","thread-G","thread-H","thread-I","thread-J",
"thread-K","thread-L","thread-M","thread-N","thread-O","thread-P","thread-Q","thread-R","thread-S","thread-T"};
libplog_init (".", "test", 10, 1);
libplog_init (".", "test", 10, 1, DEBUG);
for(int j = 0; j < THRD_COUNT; ++j)
{
pthread_create(&thrd[j], NULL, print_log, (void *)thrdname[j]);
Expand Down
1 change: 0 additions & 1 deletion src/files_handle.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ generate_file_name(char *file_name)
tv.tv_usec/1000,tv.tv_usec%1000);
strncat(file_name, strtime, max_file_name_len);
strncat(file_name, ".log", max_file_name_len);
printf("generate_file_name:%s\n", file_name);
}

const int
Expand Down
5 changes: 3 additions & 2 deletions src/lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ libplog_write(log_level_t level, char *msg)
* @update: 2016.11.28 Gavin
*/
int
libplog_init(const char *log_path, const char *project_name, const unsigned log_num, const size_t log_size)
libplog_init(const char *log_path, const char *project_name,
const unsigned log_num, const size_t log_size, log_level_t print_level)
{
memory_init ();

Expand All @@ -179,7 +180,7 @@ libplog_init(const char *log_path, const char *project_name, const unsigned log_
set_project_name(project_name);
set_log_num(log_num);
set_log_size(log_size);
set_print_level(INFO);
set_print_level(print_level);

log_fd = init_file();
/*
Expand Down

0 comments on commit e482258

Please sign in to comment.