Permalink
Browse files

Use msec_current_time to generate ts for logging

Fix for bug MB 2403

Change-Id: Icde54a11fb2b24ec12cf1ce0956d2e19a821cf41
Reviewed-on: http://review.membase.org/3727
Reviewed-by: Steve Yen <steve.yen@gmail.com>
Tested-by: Steve Yen <steve.yen@gmail.com>
  • Loading branch information...
1 parent b288887 commit 6ba1a8c810bd76e1534b87010c4740b7a16ba840 @mtaneja mtaneja committed with steveyen Nov 18, 2010
Showing with 10 additions and 6 deletions.
  1. +9 −5 log.c
  2. +1 −1 log.h
View
14 log.c
@@ -32,6 +32,8 @@
#define MAX_LOGBUF_LEN 1000
+extern volatile uint32_t msec_current_time;
+
/**
* open the errorlog
*
@@ -164,21 +166,23 @@ int log_error_write(moxi_log *mlog, const char *filename, unsigned int line,
char logbuf[MAX_LOGBUF_LEN + 10]; /* scratch buffer */
int logbuf_used = 0; /* length of scratch buffer */
+ time_t cur_ts = 0;
logbuf_used = 0;
switch(mlog->log_mode) {
case ERRORLOG_FILE:
case ERRORLOG_STDERR:
/* cache the generated timestamp */
- if (!mlog->cur_ts) {
- mlog->cur_ts = time(NULL);
+ if (!mlog->base_ts) {
+ mlog->base_ts = time(NULL);
}
+ cur_ts = mlog->base_ts + (msec_current_time/1000);
- if (mlog->cur_ts != mlog->last_generated_debug_ts) {
+ if (cur_ts != mlog->last_generated_debug_ts) {
memset(ts_debug_str, 0, sizeof(ts_debug_str));
- strftime(ts_debug_str, 254, "%Y-%m-%d %H:%M:%S", localtime(&(mlog->cur_ts)));
- mlog->last_generated_debug_ts = mlog->cur_ts;
+ strftime(ts_debug_str, 254, "%Y-%m-%d %H:%M:%S", localtime(&(cur_ts)));
+ mlog->last_generated_debug_ts = cur_ts;
}
mappend_log(logbuf, &logbuf_used, ts_debug_str);
View
2 log.h
@@ -28,7 +28,7 @@ struct moxi_log {
char *log_ident; /* syslog identifier */
char *log_file; /* if log file is specified */
int use_syslog; /* set if syslog is being used */
- time_t cur_ts; /* current timestamp */
+ time_t base_ts; /* base timestamp */
time_t last_generated_debug_ts;
};

0 comments on commit 6ba1a8c

Please sign in to comment.