File tree Expand file tree Collapse file tree 1 file changed +25
-1
lines changed Expand file tree Collapse file tree 1 file changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -329,9 +329,33 @@ static void
329
329
open_logfile (FILE * * file , const char * filename_format )
330
330
{
331
331
char * filename ;
332
+ struct stat st ;
333
+ bool rotation_requested = false;
332
334
333
335
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" );
335
359
pfree (filename );
336
360
337
361
/*
You can’t perform that action at this time.
0 commit comments