From d88e9a640861d842d0afcac49ce7549e22b3ef6f Mon Sep 17 00:00:00 2001 From: yuqing Date: Tue, 26 Aug 2014 13:46:24 +0800 Subject: [PATCH] add function log_reopen_ex --- HISTORY | 3 ++- src/logger.c | 14 ++++++++++++++ src/logger.h | 9 +++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/HISTORY b/HISTORY index 7823461..a6e66ed 100644 --- a/HISTORY +++ b/HISTORY @@ -1,5 +1,5 @@ -Version 1.06 2014-08-25 +Version 1.06 2014-08-26 * update source code from FastDFS V5.02 * add function short2buff and buff2short * add object memory pool (fast_mblock.h and fast_mblock.c) @@ -23,6 +23,7 @@ Version 1.06 2014-08-25 * socket send and recv ignore erno EINTR * http_parse_query_ex support binary buffer, and set both lengths of key and name * add function ioevent_remove + * add function log_reopen_ex Version 1.05 2012-07-08 * update source code from FastDFS V3.09 diff --git a/src/logger.c b/src/logger.c index 38a5480..781eeb2 100644 --- a/src/logger.c +++ b/src/logger.c @@ -147,6 +147,20 @@ static int log_open(LogContext *pContext) return 0; } +int log_reopen_ex(LogContext *pContext) +{ + if (*(pContext->log_filename) == '\0') + { + return ENOENT; + } + + if (pContext->log_fd >= 0 && pContext->log_fd != STDERR_FILENO) + { + close(pContext->log_fd); + } + return log_open(pContext); +} + int log_set_prefix_ex(LogContext *pContext, const char *base_path, \ const char *filename_prefix) { diff --git a/src/logger.h b/src/logger.h index cf5ed8e..27e2708 100644 --- a/src/logger.h +++ b/src/logger.h @@ -99,6 +99,8 @@ int log_init(); */ int log_init2(); +#define log_reopen() log_reopen_ex(&g_log_context) + #define log_set_prefix(base_path, filename_prefix) \ log_set_prefix_ex(&g_log_context, base_path, filename_prefix) @@ -119,6 +121,13 @@ int log_init2(); */ int log_init_ex(LogContext *pContext); +/** reopen the log file + * parameters: + * pContext: the log context + * return: 0 for success, != 0 fail +*/ +int log_reopen_ex(LogContext *pContext); + /** set log filename prefix, such as "tracker", the log filename will be * ${base_path}/logs/tracker.log * parameters: -- GitLab