parent
aa683c2324
commit
100ae31704
3
HISTORY
3
HISTORY
|
|
@ -1,10 +1,9 @@
|
||||||
|
|
||||||
Version 1.31 2016-11-24
|
Version 1.31 2016-11-13
|
||||||
* move SET_SOCKOPT_NOSIGPIPE from sockopt.c to sockopt.h
|
* move SET_SOCKOPT_NOSIGPIPE from sockopt.c to sockopt.h
|
||||||
* add function get_time_item_from_str
|
* add function get_time_item_from_str
|
||||||
* add file trylock functions
|
* add file trylock functions
|
||||||
* logger context add field: use_file_write_lock
|
* logger context add field: use_file_write_lock
|
||||||
* log support replace space chars
|
|
||||||
|
|
||||||
Version 1.30 2016-10-31
|
Version 1.30 2016-10-31
|
||||||
* modify php-fastcommon/test.php
|
* modify php-fastcommon/test.php
|
||||||
|
|
|
||||||
74
src/logger.c
74
src/logger.c
|
|
@ -249,55 +249,6 @@ void log_set_use_file_write_lock_ex(LogContext *pContext, const bool use_lock)
|
||||||
pContext->use_file_write_lock = use_lock;
|
pContext->use_file_write_lock = use_lock;
|
||||||
}
|
}
|
||||||
|
|
||||||
int log_set_space_char_pairs_ex(LogContext *pContext,
|
|
||||||
LogSpaceCharPairArray *pSpaceCharPairs)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
unsigned char src;
|
|
||||||
if (pSpaceCharPairs->count > LOG_MAX_SPACE_CHAR_PAIRS)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "file: "__FILE__", line: %d, "
|
|
||||||
"count: %d is too large, exceeds %d!\n", __LINE__,
|
|
||||||
pSpaceCharPairs->count, LOG_MAX_SPACE_CHAR_PAIRS);
|
|
||||||
return EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pContext->space_char_count > 0)
|
|
||||||
{
|
|
||||||
memset(pContext->space_char_table, 0, sizeof(pContext->space_char_table));
|
|
||||||
}
|
|
||||||
|
|
||||||
pContext->space_char_count = pSpaceCharPairs->count;
|
|
||||||
for (i=0; i<pSpaceCharPairs->count; i++)
|
|
||||||
{
|
|
||||||
src = pSpaceCharPairs->pairs[i].src;
|
|
||||||
pContext->space_char_table[src] = pSpaceCharPairs->pairs[i].dest;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void log_set_standard_space_chars_ex(LogContext *pContext,
|
|
||||||
const unsigned char dest_base)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
LogSpaceCharPairArray pair_array;
|
|
||||||
|
|
||||||
pair_array.count = 7;
|
|
||||||
pair_array.pairs[0].src = '\0';
|
|
||||||
pair_array.pairs[1].src = '\t';
|
|
||||||
pair_array.pairs[2].src = '\n';
|
|
||||||
pair_array.pairs[3].src = '\v';
|
|
||||||
pair_array.pairs[4].src = '\f';
|
|
||||||
pair_array.pairs[5].src = '\r';
|
|
||||||
pair_array.pairs[6].src = ' ';
|
|
||||||
|
|
||||||
for (i=0; i<pair_array.count; i++) {
|
|
||||||
pair_array.pairs[i].dest = dest_base + i;
|
|
||||||
}
|
|
||||||
|
|
||||||
log_set_space_char_pairs_ex(pContext, &pair_array);
|
|
||||||
}
|
|
||||||
|
|
||||||
void log_set_time_precision(LogContext *pContext, const int time_precision)
|
void log_set_time_precision(LogContext *pContext, const int time_precision)
|
||||||
{
|
{
|
||||||
pContext->time_precision = time_precision;
|
pContext->time_precision = time_precision;
|
||||||
|
|
@ -1053,29 +1004,8 @@ static void doLogEx(LogContext *pContext, struct timeval *tv, \
|
||||||
buff_len = sprintf(pContext->pcurrent_buff, "%s - ", caption);
|
buff_len = sprintf(pContext->pcurrent_buff, "%s - ", caption);
|
||||||
pContext->pcurrent_buff += buff_len;
|
pContext->pcurrent_buff += buff_len;
|
||||||
}
|
}
|
||||||
|
memcpy(pContext->pcurrent_buff, text, text_len);
|
||||||
if (pContext->space_char_count > 0)
|
pContext->pcurrent_buff += text_len;
|
||||||
{
|
|
||||||
const unsigned char *p;
|
|
||||||
const unsigned char *end;
|
|
||||||
end = (const unsigned char *)text + text_len;
|
|
||||||
for (p=(const unsigned char *)text; p<end; p++)
|
|
||||||
{
|
|
||||||
if (pContext->space_char_table[*p] != 0)
|
|
||||||
{
|
|
||||||
*pContext->pcurrent_buff++ = pContext->space_char_table[*p];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
*pContext->pcurrent_buff++ = *p;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
memcpy(pContext->pcurrent_buff, text, text_len);
|
|
||||||
pContext->pcurrent_buff += text_len;
|
|
||||||
}
|
|
||||||
*pContext->pcurrent_buff++ = '\n';
|
*pContext->pcurrent_buff++ = '\n';
|
||||||
|
|
||||||
if (!pContext->log_to_cache || bNeedSync)
|
if (!pContext->log_to_cache || bNeedSync)
|
||||||
|
|
|
||||||
50
src/logger.h
50
src/logger.h
|
|
@ -28,25 +28,11 @@ extern "C" {
|
||||||
#define LOG_COMPRESS_FLAGS_ENABLED 1
|
#define LOG_COMPRESS_FLAGS_ENABLED 1
|
||||||
#define LOG_COMPRESS_FLAGS_NEW_THREAD 2
|
#define LOG_COMPRESS_FLAGS_NEW_THREAD 2
|
||||||
|
|
||||||
#define LOG_MAX_SPACE_CHAR_PAIRS 16
|
|
||||||
|
|
||||||
struct log_context;
|
struct log_context;
|
||||||
|
|
||||||
//log header line callback
|
//log header line callback
|
||||||
typedef void (*LogHeaderCallback)(struct log_context *pContext);
|
typedef void (*LogHeaderCallback)(struct log_context *pContext);
|
||||||
|
|
||||||
typedef struct log_space_char_pair
|
|
||||||
{
|
|
||||||
unsigned char src;
|
|
||||||
unsigned char dest;
|
|
||||||
} LogSpaceCharPair;
|
|
||||||
|
|
||||||
typedef struct log_space_char_pair_array
|
|
||||||
{
|
|
||||||
int count;
|
|
||||||
LogSpaceCharPair pairs[LOG_MAX_SPACE_CHAR_PAIRS];
|
|
||||||
} LogSpaceCharPairArray;
|
|
||||||
|
|
||||||
typedef struct log_context
|
typedef struct log_context
|
||||||
{
|
{
|
||||||
/* log level value please see: sys/syslog.h
|
/* log level value please see: sys/syslog.h
|
||||||
|
|
@ -119,16 +105,6 @@ typedef struct log_context
|
||||||
* compress the log files before N days
|
* compress the log files before N days
|
||||||
* */
|
* */
|
||||||
int compress_log_days_before;
|
int compress_log_days_before;
|
||||||
|
|
||||||
/*
|
|
||||||
* space char pairs count
|
|
||||||
* */
|
|
||||||
int space_char_count;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* space char table to replace
|
|
||||||
* */
|
|
||||||
unsigned char space_char_table[256];
|
|
||||||
} LogContext;
|
} LogContext;
|
||||||
|
|
||||||
extern LogContext g_log_context;
|
extern LogContext g_log_context;
|
||||||
|
|
@ -164,12 +140,6 @@ int log_init2();
|
||||||
#define log_set_use_file_write_lock(use_lock) \
|
#define log_set_use_file_write_lock(use_lock) \
|
||||||
log_set_use_file_write_lock_ex(&g_log_context, use_lock)
|
log_set_use_file_write_lock_ex(&g_log_context, use_lock)
|
||||||
|
|
||||||
#define log_set_space_char_pairs(pSpaceCharPairs) \
|
|
||||||
log_set_space_char_pairs_ex(&g_log_context, pSpaceCharPairs)
|
|
||||||
|
|
||||||
#define log_set_standard_space_chars(dest_base) \
|
|
||||||
log_set_standard_space_chars_ex(&g_log_context, dest_base)
|
|
||||||
|
|
||||||
#define log_header(pContext, header, header_len) \
|
#define log_header(pContext, header, header_len) \
|
||||||
log_it_ex2(pContext, NULL, header, header_len, false, false)
|
log_it_ex2(pContext, NULL, header, header_len, false, false)
|
||||||
|
|
||||||
|
|
@ -224,26 +194,6 @@ void log_set_cache_ex(LogContext *pContext, const bool bLogCache);
|
||||||
*/
|
*/
|
||||||
void log_set_use_file_write_lock_ex(LogContext *pContext, const bool use_lock);
|
void log_set_use_file_write_lock_ex(LogContext *pContext, const bool use_lock);
|
||||||
|
|
||||||
|
|
||||||
/** set space char pairs to replace
|
|
||||||
* parameters:
|
|
||||||
* pContext: the log context
|
|
||||||
* pSpaceCharPairs: the space char pairs
|
|
||||||
* return: 0 for success, != 0 fail
|
|
||||||
*/
|
|
||||||
int log_set_space_char_pairs_ex(LogContext *pContext,
|
|
||||||
LogSpaceCharPairArray *pSpaceCharPairs);
|
|
||||||
|
|
||||||
|
|
||||||
/** set standard space chars to replace
|
|
||||||
* parameters:
|
|
||||||
* pContext: the log context
|
|
||||||
* dest_base: the dest base char
|
|
||||||
* return: 0 for success, != 0 fail
|
|
||||||
*/
|
|
||||||
void log_set_standard_space_chars_ex(LogContext *pContext,
|
|
||||||
const unsigned char dest_base);
|
|
||||||
|
|
||||||
/** set time precision
|
/** set time precision
|
||||||
* parameters:
|
* parameters:
|
||||||
* pContext: the log context
|
* pContext: the log context
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue