Re: log_filename_prefix --> log_filename + strftime()

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Ed L(dot)" <pgsql(at)bluepolka(dot)net>
Cc: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, pgsql-patches(at)postgresql(dot)org, Jan Wieck <JanWieck(at)Yahoo(dot)com>, Andreas Pflug <pgadmin(at)pse-consulting(dot)de>
Subject: Re: log_filename_prefix --> log_filename + strftime()
Date: 2004-09-21 00:22:42
Message-ID: 23668.1095726162@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-patches

"Ed L." <pgsql(at)bluepolka(dot)net> writes:
> I have a 5-line check-last-filename patch, but it's so small you probably
> just want to add it yourself?

Yeah, it's pretty trivial. I just applied the attached.

regards, tom lane

Index: syslogger.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/backend/postmaster/syslogger.c,v
retrieving revision 1.8
diff -c -r1.8 syslogger.c
*** syslogger.c 31 Aug 2004 04:53:44 -0000 1.8
--- syslogger.c 21 Sep 2004 00:20:04 -0000
***************
*** 81,86 ****
--- 81,88 ----

static FILE *syslogFile = NULL;

+ static char *last_file_name = NULL;
+
/* These must be exported for EXEC_BACKEND case ... annoying */
#ifndef WIN32
int syslogPipe[2] = {-1, -1};
***************
*** 761,767 ****
else
filename = logfile_getname(time(NULL));

! if (Log_truncate_on_rotation && time_based_rotation)
fh = fopen(filename, "w");
else
fh = fopen(filename, "a");
--- 763,782 ----
else
filename = logfile_getname(time(NULL));

! /*
! * Decide whether to overwrite or append. We can overwrite if (a)
! * Log_truncate_on_rotation is set, (b) the rotation was triggered by
! * elapsed time and not something else, and (c) the computed file name
! * is different from what we were previously logging into.
! *
! * Note: during the first rotation after forking off from the postmaster,
! * last_file_name will be NULL. (We don't bother to set it in the
! * postmaster because it ain't gonna work in the EXEC_BACKEND case.)
! * So we will always append in that situation, even though truncating
! * would usually be safe.
! */
! if (Log_truncate_on_rotation && time_based_rotation &&
! last_file_name != NULL && strcmp(filename, last_file_name) != 0)
fh = fopen(filename, "w");
else
fh = fopen(filename, "a");
***************
*** 806,812 ****

set_next_rotation_time();

! pfree(filename);
}


--- 821,830 ----

set_next_rotation_time();

! /* instead of pfree'ing filename, remember it for next time */
! if (last_file_name != NULL)
! pfree(last_file_name);
! last_file_name = filename;
}


***************
*** 854,859 ****
--- 872,878 ----
set_next_rotation_time(void)
{
pg_time_t now;
+ struct pg_tm *tm;
int rotinterval;

/* nothing to do if time-based rotation is disabled */
***************
*** 863,875 ****
/*
* The requirements here are to choose the next time > now that is a
* "multiple" of the log rotation interval. "Multiple" can be interpreted
! * fairly loosely --- in particular, for intervals larger than an hour,
! * it might be interesting to align to local time instead of GMT.
*/
rotinterval = Log_RotationAge * 60; /* convert to seconds */
now = time(NULL);
now -= now % rotinterval;
now += rotinterval;
next_rotation_time = now;
}

--- 882,897 ----
/*
* The requirements here are to choose the next time > now that is a
* "multiple" of the log rotation interval. "Multiple" can be interpreted
! * fairly loosely. In this version we align to local time rather than
! * GMT.
*/
rotinterval = Log_RotationAge * 60; /* convert to seconds */
now = time(NULL);
+ tm = pg_localtime(&now);
+ now += tm->tm_gmtoff;
now -= now % rotinterval;
now += rotinterval;
+ now -= tm->tm_gmtoff;
next_rotation_time = now;
}

In response to

Browse pgsql-patches by date

  From Date Subject
Next Message Zhenbang Wei 2004-09-21 01:42:14 Update postgres-zh_TW.po for 8.0
Previous Message Ed L. 2004-09-21 00:04:58 Re: log_filename_prefix --> log_filename + strftime()