diff options
author | antirez <antirez@gmail.com> | 2014-05-22 18:48:37 +0200 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2014-05-23 09:26:04 +0200 |
commit | 9996c37e74d3bf44e32850417c115b20e0c795ff (patch) | |
tree | 06e07cd3e992720353199654f1bebf0ae8ee99ef | |
parent | 33f63ff9889a79910bc881d372011ff2efec55e1 (diff) | |
download | redis-9996c37e74d3bf44e32850417c115b20e0c795ff.tar.gz |
Tag every log line with role.
Every log contains, just after the pid, a single character that provides
information about the role of an instance:
S - Slave
M - Master
C - Writing child
X - Sentinel
-rw-r--r-- | src/redis.c | 13 | ||||
-rw-r--r-- | src/redis.h | 1 |
2 files changed, 13 insertions, 1 deletions
diff --git a/src/redis.c b/src/redis.c index 7ffaea023..19c929739 100644 --- a/src/redis.c +++ b/src/redis.c @@ -304,11 +304,21 @@ void redisLogRaw(int level, const char *msg) { } else { int off; struct timeval tv; + int role_char; + pid_t pid = getpid(); 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); + if (server.sentinel_mode) { + role_char = 'X'; /* Sentinel. */ + } else if (pid != server.pid) { + role_char = 'C'; /* RDB / AOF writing child. */ + } else { + role_char = (server.masterhost ? 'S':'M'); /* Slave or Master. */ + } + fprintf(fp,"%d:%c %s %c %s\n", + (int)getpid(),role_char, buf,c[level],msg); } fflush(fp); @@ -1687,6 +1697,7 @@ void initServer() { server.syslog_facility); } + server.pid = getpid(); server.current_client = NULL; server.clients = listCreate(); server.clients_to_close = listCreate(); diff --git a/src/redis.h b/src/redis.h index aede36b0b..cdf7cb5c3 100644 --- a/src/redis.h +++ b/src/redis.h @@ -619,6 +619,7 @@ struct clusterState; struct redisServer { /* General */ + pid_t pid; /* Main process pid. */ char *configfile; /* Absolute config file path, or NULL */ int hz; /* serverCron() calls frequency in hertz */ redisDb *db; |