Re: log_filename_prefix --> log_filename + strftime() - Mailing list pgsql-patches

From Tom Lane
Subject Re: log_filename_prefix --> log_filename + strftime()
Date
Msg-id 23668.1095726162@sss.pgh.pa.us
Whole thread Raw
In response to Re: log_filename_prefix --> log_filename + strftime()  ("Ed L." <pgsql@bluepolka.net>)
List pgsql-patches
"Ed L." <pgsql@bluepolka.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;
  }


pgsql-patches by date:

Previous
From: "Ed L."
Date:
Subject: Re: log_filename_prefix --> log_filename + strftime()
Next
From: Zhenbang Wei
Date:
Subject: Update postgres-zh_TW.po for 8.0