logger judge log_level in function log_it_ex and log_it_ex1
parent
9f30515f88
commit
7a0fae8f01
3
HISTORY
3
HISTORY
|
|
@ -1,4 +1,7 @@
|
|||
|
||||
Version 1.35 2017-02-09
|
||||
* logger judge log_level in function log_it_ex and log_it_ex1
|
||||
|
||||
Version 1.34 2017-02-06
|
||||
* ini_file_reader: LOCAL_IP support CIDR addresses
|
||||
* ini_file_reader: return the last when get single value,
|
||||
|
|
|
|||
16
src/logger.c
16
src/logger.c
|
|
@ -1051,7 +1051,12 @@ void log_it_ex1(LogContext *pContext, const int priority, \
|
|||
bool bNeedSync;
|
||||
char *caption;
|
||||
|
||||
switch(priority)
|
||||
if (pContext->log_level < priority)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (priority)
|
||||
{
|
||||
case LOG_DEBUG:
|
||||
bNeedSync = true;
|
||||
|
|
@ -1100,8 +1105,13 @@ void log_it_ex(LogContext *pContext, const int priority, const char *format, ...
|
|||
char text[LINE_MAX];
|
||||
char *caption;
|
||||
int len;
|
||||
|
||||
va_list ap;
|
||||
|
||||
if (pContext->log_level < priority)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
va_start(ap, format);
|
||||
len = vsnprintf(text, sizeof(text), format, ap);
|
||||
va_end(ap);
|
||||
|
|
@ -1110,7 +1120,7 @@ void log_it_ex(LogContext *pContext, const int priority, const char *format, ...
|
|||
len = sizeof(text) - 1;
|
||||
}
|
||||
|
||||
switch(priority)
|
||||
switch (priority)
|
||||
{
|
||||
case LOG_DEBUG:
|
||||
bNeedSync = true;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ INC_PATH = -I/usr/include/fastcommon
|
|||
LIB_PATH = -lfastcommon -lpthread
|
||||
|
||||
ALL_PRGS = test_allocator test_skiplist test_multi_skiplist test_mblock test_blocked_queue \
|
||||
test_id_generator test_ini_parser test_char_convert test_char_convert_loader
|
||||
test_id_generator test_ini_parser test_char_convert test_char_convert_loader test_logger
|
||||
|
||||
all: $(ALL_PRGS)
|
||||
.c:
|
||||
|
|
|
|||
|
|
@ -21,17 +21,6 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
log_init();
|
||||
g_log_context.log_level = LOG_DEBUG;
|
||||
log_take_over_stderr();
|
||||
log_take_over_stdout();
|
||||
log_set_compress_log_flags(LOG_COMPRESS_FLAGS_ENABLED | LOG_COMPRESS_FLAGS_NEW_THREAD);
|
||||
|
||||
printf("sizeof(LogContext): %d, time_precision: %d, compress_log_flags: %d, "
|
||||
"use_file_write_lock: %d\n", (int)sizeof(LogContext),
|
||||
g_log_context.time_precision,
|
||||
g_log_context.compress_log_flags,
|
||||
g_log_context.use_file_write_lock);
|
||||
|
||||
if ((result=iniLoadFromFile(szFilename, &context)) != 0)
|
||||
{
|
||||
return result;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,39 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <time.h>
|
||||
#include <inttypes.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/stat.h>
|
||||
#include "logger.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char buff[256];
|
||||
int len;
|
||||
|
||||
log_init();
|
||||
//g_log_context.log_level = LOG_DEBUG;
|
||||
g_log_context.log_level = LOG_INFO;
|
||||
log_take_over_stderr();
|
||||
log_take_over_stdout();
|
||||
log_set_compress_log_flags(LOG_COMPRESS_FLAGS_ENABLED | LOG_COMPRESS_FLAGS_NEW_THREAD);
|
||||
|
||||
printf("sizeof(LogContext): %d, time_precision: %d, compress_log_flags: %d, "
|
||||
"use_file_write_lock: %d\n", (int)sizeof(LogContext),
|
||||
g_log_context.time_precision,
|
||||
g_log_context.compress_log_flags,
|
||||
g_log_context.use_file_write_lock);
|
||||
|
||||
log_it_ex(&g_log_context, LOG_DEBUG,
|
||||
"by log_it_ex, timestamp: %d", (int)time(NULL));
|
||||
|
||||
len = sprintf(buff, "this is by log_it_ex1, "
|
||||
"timestamp: %d", (int)time(NULL));
|
||||
log_it_ex1(&g_log_context, LOG_INFO, buff, len);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue