Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
9c104c68
Commit
9c104c68
authored
Feb 09, 2011
by
antirez
Browse files
introduced a new logging function for big messages
parent
a8cc969c
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/redis.c
View file @
9c104c68
...
@@ -192,24 +192,20 @@ struct redisCommand redisCommandTable[] = {
...
@@ -192,24 +192,20 @@ struct redisCommand redisCommandTable[] = {
/*============================ Utility functions ============================ */
/*============================ Utility functions ============================ */
void redisLog(int level, const char *fmt, ...) {
/* Low level logging. To use only for very big messages, otherwise
* redisLog() is to prefer. */
void redisLogRaw(int level, const char *msg) {
const int syslogLevelMap[] = { LOG_DEBUG, LOG_INFO, LOG_NOTICE, LOG_WARNING };
const int syslogLevelMap[] = { LOG_DEBUG, LOG_INFO, LOG_NOTICE, LOG_WARNING };
const char *c = ".-*#";
const char *c = ".-*#";
time_t now = time(NULL);
time_t now = time(NULL);
va_list ap;
FILE *fp;
FILE *fp;
char buf[64];
char buf[64];
char msg[REDIS_MAX_LOGMSG_LEN];
if (level < server.verbosity) return;
if (level < server.verbosity) return;
fp = (server.logfile == NULL) ? stdout : fopen(server.logfile,"a");
fp = (server.logfile == NULL) ? stdout : fopen(server.logfile,"a");
if (!fp) return;
if (!fp) return;
va_start(ap, fmt);
vsnprintf(msg, sizeof(msg), fmt, ap);
va_end(ap);
strftime(buf,sizeof(buf),"%d %b %H:%M:%S",localtime(&now));
strftime(buf,sizeof(buf),"%d %b %H:%M:%S",localtime(&now));
fprintf(fp,"[%d] %s %c %s\n",(int)getpid(),buf,c[level],msg);
fprintf(fp,"[%d] %s %c %s\n",(int)getpid(),buf,c[level],msg);
fflush(fp);
fflush(fp);
...
@@ -219,6 +215,22 @@ void redisLog(int level, const char *fmt, ...) {
...
@@ -219,6 +215,22 @@ void redisLog(int level, const char *fmt, ...) {
if (server.syslog_enabled) syslog(syslogLevelMap[level], "%s", msg);
if (server.syslog_enabled) syslog(syslogLevelMap[level], "%s", msg);
}
}
/* Like redisLogRaw() but with printf-alike support. This is the funciton that
* is used across the code. The raw version is only used in order to dump
* the INFO output on crash. */
void redisLog(int level, const char *fmt, ...) {
va_list ap;
char msg[REDIS_MAX_LOGMSG_LEN];
if (level < server.verbosity) return;
va_start(ap, fmt);
vsnprintf(msg, sizeof(msg), fmt, ap);
va_end(ap);
redisLogRaw(level,msg);
}
/* Redis generally does not try to recover from out of memory conditions
/* Redis generally does not try to recover from out of memory conditions
* when allocating objects or strings, it is not clear if it will be possible
* when allocating objects or strings, it is not clear if it will be possible
* to report this condition to the client since the networking layer itself
* to report this condition to the client since the networking layer itself
...
@@ -1725,7 +1737,7 @@ void segvHandler(int sig, siginfo_t *info, void *secret) {
...
@@ -1725,7 +1737,7 @@ void segvHandler(int sig, siginfo_t *info, void *secret) {
redisLog(REDIS_WARNING,
redisLog(REDIS_WARNING,
"======= Ooops! Redis %s got signal: -%d- =======", REDIS_VERSION, sig);
"======= Ooops! Redis %s got signal: -%d- =======", REDIS_VERSION, sig);
infostring = genRedisInfoString("all");
infostring = genRedisInfoString("all");
redisLog(REDIS_WARNING,
"%s",
infostring);
redisLog
Raw
(REDIS_WARNING, infostring);
/* It's not safe to sdsfree() the returned string under memory
/* It's not safe to sdsfree() the returned string under memory
* corruption conditions. Let it leak as we are going to abort */
* corruption conditions. Let it leak as we are going to abort */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment