none
Redis server log file rotation on Windows RRS feed

  • Question

  • We are using Redis 3.2 (64 bit) (https://github.com/MSOpenTech/redis/releases) on Windows Server 2012 R2 Standard Azure VM, for in-memory data caching.

    Have been able to write redis-server logs by setting the logfile parameter in redis.conf file but, could not specify log file max size & subsequent rollover. Would want to know whether there is a way to specify log file rotation in Redis conf / probably pass that as a parameter when starting the Redis server daemon process.

    It would really help to get any suggestions on this front.

    Thanks & Regards,

    Webmaster


    What's-On

    Thursday, November 3, 2016 7:14 AM

All replies

  • Hi,

    Thanks for posting here.

    Redis on Windows is as same as the one from redis.io, only is re-compiled using VC++ for Windows by MS. So According to the annotation information of redis offical configuration file, there are not any configuration variables which can be specify log file max size & subsequent rollover.

    Here is my workaround way to split log via windows cmd pipeline and a custom program if log size over a specified size.

    1. Configure redis.config to disable `logfile` variable, the logs will out to stdout.

    2. Using cmd pipeline to redirect the stdout log to a custom program with logfile path & max size number as below.

    redis-server | ./mylog.exe . 10000

    My custom program in C as below.

    #include<stdio.h>
    #include<time.h>
    
    //const long MAX_SIZE = 100;
    
    int main(int argc, char *argv[]) {
    	char *path;
    	long max_size;
    	if(argc > 2) {
    		path = argv[1];
    		sscanf(argv[2], "%ld", &max_size);	
    	} else {
    		return 1;
    	}
    	FILE *file;
    	char filename[20];
    	int num = 0;
    	sprintf(filename, "%s/%ld.log", path, time(NULL)+num++);
    	file = fopen(filename, "w");
    	printf("New Logfile: %s\n", filename);
    	int ch;
    	long size = 0;
    	while((ch = getchar()) != EOF) {
    		size ++;
    		fprintf(file, "%c", ch);
    		if(ch == '\n' && size >= max_size) {
    			fclose(file);
    			sprintf(filename, "%s/%ld.log", path, time(NULL)+num++);
    			file = fopen(filename, "w");
    			printf("New Logfile: %s\n", filename);
    			size = 0;
    		}
    	}
    	fclose(file);
    	return 0;
    }
    
    Hope it helps.


    Wednesday, November 16, 2016 7:07 AM
    Moderator
  • Hi, 

    I see it's a few years old question and answer, but I am having similar issue with Redis log rotation implementation in windows. With redirecting log to stdio it works as described if you start Redis server from cmd and use cmd pipeline, but if Redis is running as a service, piping to a custom program doesn't work.  

    Is there any way to resolve this with Redis running as a windows service? 

    Thanks!    

    Friday, August 14, 2020 9:17 PM