Skip to content

Commit 1a6ee7a

Browse files
committed
Rotation by size works
1 parent cfe9b85 commit 1a6ee7a

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

utils/logger.c

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,9 +329,33 @@ static void
329329
open_logfile(FILE **file, const char *filename_format)
330330
{
331331
char *filename;
332+
struct stat st;
333+
bool rotation_requested = false;
332334

333335
filename = logfile_getname(filename_format, time(NULL));
334-
*file = logfile_open(filename, "a");
336+
337+
/* First check for rotation by size */
338+
if (log_rotation_size > 0)
339+
{
340+
if (stat(filename, &st) == -1)
341+
{
342+
if (errno == ENOENT)
343+
{
344+
/* There is no file "filename" and rotation does not need */
345+
}
346+
else
347+
elog(ERROR, "cannot stat log file \"%s\": %s",
348+
filename, strerror(errno));
349+
}
350+
/* Found log file "filename" */
351+
else
352+
rotation_requested = (st.st_size >= log_rotation_size * 1024L);
353+
}
354+
355+
if (rotation_requested)
356+
*file = logfile_open(filename, "w");
357+
else
358+
*file = logfile_open(filename, "a");
335359
pfree(filename);
336360

337361
/*

0 commit comments

Comments
 (0)