Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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...
commit 6ba1a8c810bd76e1534b87010c4740b7a16ba840 1 parent b288887
mtaneja authored November 18, 2010 steveyen committed November 18, 2010

Showing 2 changed files with 10 additions and 6 deletions. Show diff stats Hide diff stats

  1. 14  log.c
  2. 2  log.h
14  log.c
@@ -32,6 +32,8 @@
32 32
 
33 33
 #define MAX_LOGBUF_LEN 1000
34 34
 
  35
+extern volatile uint32_t msec_current_time;
  36
+
35 37
 /**
36 38
  * open the errorlog
37 39
  *
@@ -164,6 +166,7 @@ int log_error_write(moxi_log *mlog, const char *filename, unsigned int line,
164 166
 
165 167
     char logbuf[MAX_LOGBUF_LEN + 10]; /* scratch buffer */
166 168
     int  logbuf_used = 0;             /* length of scratch buffer */
  169
+    time_t cur_ts = 0;
167 170
 
168 171
     logbuf_used = 0;
169 172
 
@@ -171,14 +174,15 @@ int log_error_write(moxi_log *mlog, const char *filename, unsigned int line,
171 174
         case ERRORLOG_FILE:
172 175
         case ERRORLOG_STDERR:
173 176
             /* cache the generated timestamp */
174  
-            if (!mlog->cur_ts) {
175  
-                mlog->cur_ts = time(NULL);
  177
+            if (!mlog->base_ts) {
  178
+                mlog->base_ts = time(NULL);
176 179
             }
  180
+            cur_ts = mlog->base_ts + (msec_current_time/1000);
177 181
 
178  
-            if (mlog->cur_ts != mlog->last_generated_debug_ts) {
  182
+            if (cur_ts != mlog->last_generated_debug_ts) {
179 183
                 memset(ts_debug_str, 0, sizeof(ts_debug_str));
180  
-                strftime(ts_debug_str, 254, "%Y-%m-%d %H:%M:%S", localtime(&(mlog->cur_ts)));
181  
-                mlog->last_generated_debug_ts = mlog->cur_ts;
  184
+                strftime(ts_debug_str, 254, "%Y-%m-%d %H:%M:%S", localtime(&(cur_ts)));
  185
+                mlog->last_generated_debug_ts = cur_ts;
182 186
             }
183 187
 
184 188
             mappend_log(logbuf, &logbuf_used, ts_debug_str);
2  log.h
@@ -28,7 +28,7 @@ struct moxi_log {
28 28
     char *log_ident;    /* syslog identifier */
29 29
     char *log_file;     /* if log file is specified */
30 30
     int use_syslog;     /* set if syslog is being used */
31  
-    time_t cur_ts;      /* current timestamp */
  31
+    time_t base_ts;     /* base timestamp */
32 32
     time_t last_generated_debug_ts;
33 33
 };
34 34
 

0 notes on commit 6ba1a8c

Please sign in to comment.
Something went wrong with that request. Please try again.