Skip to content

Commit

Permalink
don't open/close log file if log level is not matched
Browse files Browse the repository at this point in the history
  • Loading branch information
antirez committed Jul 22, 2010
1 parent de4aebe commit fe2173a
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions redis.c
Original file line number Diff line number Diff line change
Expand Up @@ -1058,23 +1058,22 @@ static int ll2string(char *s, size_t len, long long value) {
static void redisLog(int level, const char *fmt, ...) {
va_list ap;
FILE *fp;
char *c = ".-*#";
char buf[64];
time_t now;

if (level < server.verbosity) return;

fp = (server.logfile == NULL) ? stdout : fopen(server.logfile,"a");
if (!fp) return;

va_start(ap, fmt);
if (level >= server.verbosity) {
char *c = ".-*#";
char buf[64];
time_t now;

now = time(NULL);
strftime(buf,64,"%d %b %H:%M:%S",localtime(&now));
fprintf(fp,"[%d] %s %c ",(int)getpid(),buf,c[level]);
vfprintf(fp, fmt, ap);
fprintf(fp,"\n");
fflush(fp);
}
now = time(NULL);
strftime(buf,64,"%d %b %H:%M:%S",localtime(&now));
fprintf(fp,"[%d] %s %c ",(int)getpid(),buf,c[level]);
vfprintf(fp, fmt, ap);
fprintf(fp,"\n");
fflush(fp);
va_end(ap);

if (server.logfile) fclose(fp);
Expand Down

0 comments on commit fe2173a

Please sign in to comment.