提交 df35d873 编写于 作者: A antirez

Print milliseconds of the current second in log lines timestamps. Sometimes...

Print milliseconds of the current second in log lines timestamps. Sometimes precise timing is very important for debugging.
上级 3c413d59
......@@ -251,7 +251,6 @@ struct redisCommand redisCommandTable[] = {
void redisLogRaw(int level, const char *msg) {
const int syslogLevelMap[] = { LOG_DEBUG, LOG_INFO, LOG_NOTICE, LOG_WARNING };
const char *c = ".-*#";
time_t now = time(NULL);
FILE *fp;
char buf[64];
int rawmode = (level & REDIS_LOG_RAW);
......@@ -265,7 +264,12 @@ void redisLogRaw(int level, const char *msg) {
if (rawmode) {
fprintf(fp,"%s",msg);
} else {
strftime(buf,sizeof(buf),"%d %b %H:%M:%S",localtime(&now));
int off;
struct timeval tv;
gettimeofday(&tv,NULL);
off = strftime(buf,sizeof(buf),"%d %b %H:%M:%S.",localtime(&tv.tv_sec));
snprintf(buf+off,sizeof(buf)-off,"%03d",(int)tv.tv_usec/1000);
fprintf(fp,"[%d] %s %c %s\n",(int)getpid(),buf,c[level],msg);
}
fflush(fp);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册