Skip to content

Commit

Permalink
add SOFA_PBRPC_ENABLE_DETAILED_LOGGING macro
Browse files Browse the repository at this point in the history
  • Loading branch information
qinzuoyan committed Jun 7, 2016
1 parent e8ec453 commit 446448c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ OPT ?= -O2 # (A) Production use (optimized mode)
# OPT ?= -O2 -g2 # (C) Profiling mode: opt, but generate debugging symbols
#-----------------------------------------------

#-----------------------------------------------
# Customized macro switch:
# SOFA_PBRPC_ENABLE_DETAILED_LOGGING : print current-time and thread-id in logging header
# SOFA_PBRPC_ENABLE_FUNCTION_TRACE : print trace log when enter and leave function
# SOFA_PBRPC_USE_SPINLOCK : use SpinLock as FastLock
#
CXXFLAGS ?= -DSOFA_PBRPC_ENABLE_DETAILED_LOGGING
#-----------------------------------------------

#-----------------------------------------------
# !!! Do not change the following lines !!!
#-----------------------------------------------
Expand Down
28 changes: 23 additions & 5 deletions src/sofa/pbrpc/common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
#include <cstdarg>
#include <cstdlib>

#if defined( SOFA_PBRPC_ENABLE_DETAILED_LOGGING )
#include <time.h>
#include <sys/time.h>
#include <pthread.h>
#endif

#include <sofa/pbrpc/common.h>
#include <sofa/pbrpc/ptime.h>

Expand Down Expand Up @@ -42,16 +48,28 @@ void default_log_handler(
"INFO", "TRACE", "DEBUG" };
char buf[1024];
vsnprintf(buf, 1024, fmt, ap);
#if 0
fprintf(stderr, "libsofa_pbrpc %s %s %s:%d] %s\n",
#if defined( SOFA_PBRPC_ENABLE_DETAILED_LOGGING )
struct timeval now_tv;
gettimeofday(&now_tv, NULL);
const time_t seconds = now_tv.tv_sec;
struct tm t;
localtime_r(&seconds, &t);
fprintf(stderr, "libsofa_pbrpc %s %04d/%02d/%02d-%02d:%02d:%02d.%06d %llx %s:%d] %s\n",
level_names[level],
boost::posix_time::to_simple_string(
boost::posix_time::microsec_clock::local_time()).c_str(),
t.tm_year + 1900,
t.tm_mon + 1,
t.tm_mday,
t.tm_hour,
t.tm_min,
t.tm_sec,
static_cast<int>(now_tv.tv_usec),
static_cast<long long unsigned int>(pthread_self()),
filename, line, buf);
#endif
#else
fprintf(stderr, "libsofa_pbrpc %s %s:%d] %s\n",
level_names[level],
filename, line, buf);
#endif
fflush(stderr);

if (level == ::sofa::pbrpc::LOG_LEVEL_FATAL)
Expand Down

0 comments on commit 446448c

Please sign in to comment.