use newest logger from libfastcommon
parent
fd38a009da
commit
d263acfaa2
4
HISTORY
4
HISTORY
|
|
@ -1,6 +1,8 @@
|
||||||
|
|
||||||
Version 5.03 2014-08-02
|
Version 5.03 2014-08-11
|
||||||
* network send and recv retry when error EINTR happen
|
* network send and recv retry when error EINTR happen
|
||||||
|
* support mac OS Darwin
|
||||||
|
* use newest logger from libfastcommon
|
||||||
|
|
||||||
Version 5.02 2014-07-20
|
Version 5.02 2014-07-20
|
||||||
* corect README spell mistake
|
* corect README spell mistake
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,10 @@ FAST_STATIC_OBJS = ../common/hash.o ../common/chain.o \
|
||||||
../common/base64.o ../common/sched_thread.o \
|
../common/base64.o ../common/sched_thread.o \
|
||||||
../common/http_func.o ../common/md5.o \
|
../common/http_func.o ../common/md5.o \
|
||||||
../common/pthread_func.o ../common/local_ip_func.o \
|
../common/pthread_func.o ../common/local_ip_func.o \
|
||||||
../common/avl_tree.o ../common/connection_pool.o
|
../common/avl_tree.o ../common/connection_pool.o \
|
||||||
|
../common/ioevent.o ../common/ioevent_loop.o \
|
||||||
|
../common/fast_task_queue.o ../common/fast_timer.o \
|
||||||
|
../common/process_ctrl.o ../common/fast_mblock.o
|
||||||
|
|
||||||
FDFS_STATIC_OBJS = ../common/fdfs_global.o ../common/fdfs_http_shared.o \
|
FDFS_STATIC_OBJS = ../common/fdfs_global.o ../common/fdfs_http_shared.o \
|
||||||
../common/mime_file_parser.o ../tracker/tracker_proto.o \
|
../common/mime_file_parser.o ../tracker/tracker_proto.o \
|
||||||
|
|
@ -33,7 +36,10 @@ FAST_SHARED_OBJS = ../common/hash.lo ../common/chain.lo \
|
||||||
../common/base64.lo ../common/sched_thread.lo \
|
../common/base64.lo ../common/sched_thread.lo \
|
||||||
../common/http_func.lo ../common/md5.lo \
|
../common/http_func.lo ../common/md5.lo \
|
||||||
../common/pthread_func.lo ../common/local_ip_func.lo \
|
../common/pthread_func.lo ../common/local_ip_func.lo \
|
||||||
../common/avl_tree.lo ../common/connection_pool.lo
|
../common/avl_tree.lo ../common/connection_pool.lo \
|
||||||
|
../common/ioevent.lo ../common/ioevent_loop.lo \
|
||||||
|
../common/fast_task_queue.lo ../common/fast_timer.lo \
|
||||||
|
../common/process_ctrl.lo ../common/fast_mblock.lo
|
||||||
|
|
||||||
FDFS_SHARED_OBJS = ../common/fdfs_global.lo ../common/fdfs_http_shared.lo \
|
FDFS_SHARED_OBJS = ../common/fdfs_global.lo ../common/fdfs_http_shared.lo \
|
||||||
../common/mime_file_parser.lo ../tracker/tracker_proto.lo \
|
../common/mime_file_parser.lo ../tracker/tracker_proto.lo \
|
||||||
|
|
@ -49,7 +55,10 @@ FAST_HEADER_FILES = ../common/common_define.h ../common/hash.h \
|
||||||
../common/sockopt.h ../common/sched_thread.h \
|
../common/sockopt.h ../common/sched_thread.h \
|
||||||
../common/http_func.h ../common/md5.h ../common/_os_bits.h \
|
../common/http_func.h ../common/md5.h ../common/_os_bits.h \
|
||||||
../common/local_ip_func.h ../common/avl_tree.h \
|
../common/local_ip_func.h ../common/avl_tree.h \
|
||||||
../common/connection_pool.h
|
../common/connection_pool.h ../common/ioevent.h \
|
||||||
|
../common/ioevent_loop.h ../common/fast_task_queue.h \
|
||||||
|
../common/fast_timer.h ../common/process_ctrl.h \
|
||||||
|
../common/fast_mblock.h
|
||||||
|
|
||||||
FDFS_HEADER_FILES = ../common/fdfs_define.h ../common/fdfs_global.h \
|
FDFS_HEADER_FILES = ../common/fdfs_define.h ../common/fdfs_global.h \
|
||||||
../common/mime_file_parser.h ../common/fdfs_http_shared.h \
|
../common/mime_file_parser.h ../common/fdfs_http_shared.h \
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,18 @@ int log_init()
|
||||||
return log_init_ex(&g_log_context);
|
return log_init_ex(&g_log_context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int log_init2()
|
||||||
|
{
|
||||||
|
int result;
|
||||||
|
if ((result=log_init()) != 0) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
log_take_over_stderr();
|
||||||
|
log_take_over_stdout();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int log_init_ex(LogContext *pContext)
|
int log_init_ex(LogContext *pContext)
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
|
|
@ -97,17 +109,33 @@ static int log_open(LogContext *pContext)
|
||||||
O_CREAT | O_APPEND, 0644)) < 0)
|
O_CREAT | O_APPEND, 0644)) < 0)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "open log file \"%s\" to write fail, " \
|
fprintf(stderr, "open log file \"%s\" to write fail, " \
|
||||||
"errno: %d, error info: %s", \
|
"errno: %d, error info: %s\n", \
|
||||||
pContext->log_filename, errno, STRERROR(errno));
|
pContext->log_filename, errno, STRERROR(errno));
|
||||||
pContext->log_fd = STDERR_FILENO;
|
pContext->log_fd = STDERR_FILENO;
|
||||||
return errno != 0 ? errno : EACCES;
|
return errno != 0 ? errno : EACCES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pContext->take_over_stderr) {
|
||||||
|
if (dup2(pContext->log_fd, STDERR_FILENO) < 0) {
|
||||||
|
fprintf(stderr, "file: "__FILE__", line: %d, "
|
||||||
|
"call dup2 fail, errno: %d, error info: %s\n",
|
||||||
|
__LINE__, errno, STRERROR(errno));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pContext->take_over_stdout) {
|
||||||
|
if (dup2(pContext->log_fd, STDOUT_FILENO) < 0) {
|
||||||
|
fprintf(stderr, "file: "__FILE__", line: %d, "
|
||||||
|
"call dup2 fail, errno: %d, error info: %s\n",
|
||||||
|
__LINE__, errno, STRERROR(errno));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pContext->current_size = lseek(pContext->log_fd, 0, SEEK_END);
|
pContext->current_size = lseek(pContext->log_fd, 0, SEEK_END);
|
||||||
if (pContext->current_size < 0)
|
if (pContext->current_size < 0)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "lseek file \"%s\" fail, " \
|
fprintf(stderr, "lseek file \"%s\" fail, " \
|
||||||
"errno: %d, error info: %s", \
|
"errno: %d, error info: %s\n", \
|
||||||
pContext->log_filename, errno, STRERROR(errno));
|
pContext->log_filename, errno, STRERROR(errno));
|
||||||
return errno != 0 ? errno : EACCES;
|
return errno != 0 ? errno : EACCES;
|
||||||
}
|
}
|
||||||
|
|
@ -137,6 +165,11 @@ int log_set_prefix_ex(LogContext *pContext, const char *base_path, \
|
||||||
|
|
||||||
int log_set_filename_ex(LogContext *pContext, const char *log_filename)
|
int log_set_filename_ex(LogContext *pContext, const char *log_filename)
|
||||||
{
|
{
|
||||||
|
if (log_filename == NULL) {
|
||||||
|
fprintf(stderr, "file: "__FILE__", line: %d, " \
|
||||||
|
"log_filename is NULL!\n", __LINE__);
|
||||||
|
return EINVAL;
|
||||||
|
}
|
||||||
snprintf(pContext->log_filename, MAX_PATH_SIZE, "%s", log_filename);
|
snprintf(pContext->log_filename, MAX_PATH_SIZE, "%s", log_filename);
|
||||||
return log_open(pContext);
|
return log_open(pContext);
|
||||||
}
|
}
|
||||||
|
|
@ -177,6 +210,16 @@ void log_set_header_callback(LogContext *pContext, LogHeaderCallback header_call
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void log_take_over_stderr_ex(LogContext *pContext)
|
||||||
|
{
|
||||||
|
pContext->take_over_stderr = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void log_take_over_stdout_ex(LogContext *pContext)
|
||||||
|
{
|
||||||
|
pContext->take_over_stdout = true;
|
||||||
|
}
|
||||||
|
|
||||||
void log_destroy_ex(LogContext *pContext)
|
void log_destroy_ex(LogContext *pContext)
|
||||||
{
|
{
|
||||||
if (pContext->log_fd >= 0 && pContext->log_fd != STDERR_FILENO)
|
if (pContext->log_fd >= 0 && pContext->log_fd != STDERR_FILENO)
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,12 @@ typedef struct log_context
|
||||||
/* if rotate the access log */
|
/* if rotate the access log */
|
||||||
bool rotate_immediately;
|
bool rotate_immediately;
|
||||||
|
|
||||||
|
/* if stderr to the log file */
|
||||||
|
bool take_over_stderr;
|
||||||
|
|
||||||
|
/* if stdout to the log file */
|
||||||
|
bool take_over_stdout;
|
||||||
|
|
||||||
/* time precision */
|
/* time precision */
|
||||||
char time_precision;
|
char time_precision;
|
||||||
|
|
||||||
|
|
@ -88,6 +94,11 @@ extern LogContext g_log_context;
|
||||||
*/
|
*/
|
||||||
int log_init();
|
int log_init();
|
||||||
|
|
||||||
|
/** init function using global log context, take over stderr and stdout
|
||||||
|
* return: 0 for success, != 0 fail
|
||||||
|
*/
|
||||||
|
int log_init2();
|
||||||
|
|
||||||
#define log_set_prefix(base_path, filename_prefix) \
|
#define log_set_prefix(base_path, filename_prefix) \
|
||||||
log_set_prefix_ex(&g_log_context, base_path, filename_prefix)
|
log_set_prefix_ex(&g_log_context, base_path, filename_prefix)
|
||||||
|
|
||||||
|
|
@ -96,6 +107,9 @@ int log_init();
|
||||||
|
|
||||||
#define log_set_cache(bLogCache) log_set_cache_ex(&g_log_context, bLogCache)
|
#define log_set_cache(bLogCache) log_set_cache_ex(&g_log_context, bLogCache)
|
||||||
|
|
||||||
|
#define log_take_over_stderr() log_take_over_stderr_ex(&g_log_context)
|
||||||
|
#define log_take_over_stdout() log_take_over_stdout_ex(&g_log_context)
|
||||||
|
|
||||||
#define log_destroy() log_destroy_ex(&g_log_context)
|
#define log_destroy() log_destroy_ex(&g_log_context)
|
||||||
|
|
||||||
/** init function, use stderr for output by default
|
/** init function, use stderr for output by default
|
||||||
|
|
@ -164,6 +178,16 @@ void log_set_keep_days(LogContext *pContext, const int keep_days);
|
||||||
*/
|
*/
|
||||||
void log_set_header_callback(LogContext *pContext, LogHeaderCallback header_callback);
|
void log_set_header_callback(LogContext *pContext, LogHeaderCallback header_callback);
|
||||||
|
|
||||||
|
/** set take_over_stderr to true
|
||||||
|
* return: none
|
||||||
|
*/
|
||||||
|
void log_take_over_stderr_ex(LogContext *pContext);
|
||||||
|
|
||||||
|
/** set take_over_stdout to true
|
||||||
|
* return: none
|
||||||
|
*/
|
||||||
|
void log_take_over_stdout_ex(LogContext *pContext);
|
||||||
|
|
||||||
/** destroy function
|
/** destroy function
|
||||||
* parameters:
|
* parameters:
|
||||||
* pContext: the log context
|
* pContext: the log context
|
||||||
|
|
|
||||||
|
|
@ -106,7 +106,7 @@ int main(int argc, char *argv[])
|
||||||
g_current_time = time(NULL);
|
g_current_time = time(NULL);
|
||||||
g_up_time = g_current_time;
|
g_up_time = g_current_time;
|
||||||
|
|
||||||
log_init();
|
log_init2();
|
||||||
trunk_shared_init();
|
trunk_shared_init();
|
||||||
|
|
||||||
conf_filename = argv[1];
|
conf_filename = argv[1];
|
||||||
|
|
@ -168,7 +168,7 @@ int main(int argc, char *argv[])
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
daemon_init(true);
|
daemon_init(false);
|
||||||
umask(0);
|
umask(0);
|
||||||
if ((result=write_to_pid_file(pidFilename)) != 0)
|
if ((result=write_to_pid_file(pidFilename)) != 0)
|
||||||
{
|
{
|
||||||
|
|
@ -176,16 +176,6 @@ int main(int argc, char *argv[])
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dup2(g_log_context.log_fd, STDOUT_FILENO) < 0 || \
|
|
||||||
dup2(g_log_context.log_fd, STDERR_FILENO) < 0)
|
|
||||||
{
|
|
||||||
logCrit("file: "__FILE__", line: %d, " \
|
|
||||||
"call dup2 fail, errno: %d, error info: %s, " \
|
|
||||||
"program exit!", __LINE__, errno, STRERROR(errno));
|
|
||||||
g_continue_flag = false;
|
|
||||||
return errno;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((result=storage_sync_init()) != 0)
|
if ((result=storage_sync_init()) != 0)
|
||||||
{
|
{
|
||||||
logCrit("file: "__FILE__", line: %d, " \
|
logCrit("file: "__FILE__", line: %d, " \
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,7 @@ int main(int argc, char *argv[])
|
||||||
g_up_time = g_current_time;
|
g_up_time = g_current_time;
|
||||||
srand(g_up_time);
|
srand(g_up_time);
|
||||||
|
|
||||||
log_init();
|
log_init2();
|
||||||
|
|
||||||
conf_filename = argv[1];
|
conf_filename = argv[1];
|
||||||
if ((result=get_base_path_from_conf_file(conf_filename,
|
if ((result=get_base_path_from_conf_file(conf_filename,
|
||||||
|
|
@ -188,7 +188,7 @@ int main(int argc, char *argv[])
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
daemon_init(true);
|
daemon_init(false);
|
||||||
umask(0);
|
umask(0);
|
||||||
|
|
||||||
if ((result=write_to_pid_file(pidFilename)) != 0)
|
if ((result=write_to_pid_file(pidFilename)) != 0)
|
||||||
|
|
@ -197,16 +197,6 @@ int main(int argc, char *argv[])
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dup2(g_log_context.log_fd, STDOUT_FILENO) < 0 || \
|
|
||||||
dup2(g_log_context.log_fd, STDERR_FILENO) < 0)
|
|
||||||
{
|
|
||||||
logCrit("file: "__FILE__", line: %d, " \
|
|
||||||
"call dup2 fail, errno: %d, error info: %s, " \
|
|
||||||
"program exit!", __LINE__, errno, STRERROR(errno));
|
|
||||||
g_continue_flag = false;
|
|
||||||
return errno;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((result=tracker_service_init()) != 0)
|
if ((result=tracker_service_init()) != 0)
|
||||||
{
|
{
|
||||||
logCrit("exit abnormally!\n");
|
logCrit("exit abnormally!\n");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue