@ -2,7 +2,7 @@
*
* syslogger . c
*
* The system logger ( syslogger ) is new in Postgres 8.0 . It catches all
* The system logger ( syslogger ) appeared in Postgres 8.0 . It catches all
* stderr output from the postmaster , backends , and other subprocesses
* by redirecting to a pipe , and writes it to a set of logfiles .
* It ' s possible to have size and age limits for the logfile configured
@ -91,6 +91,7 @@ static bool pipe_eof_seen = false;
static bool rotation_disabled = false ;
static FILE * syslogFile = NULL ;
static FILE * csvlogFile = NULL ;
NON_EXEC_STATIC pg_time_t first_syslogger_file_time = 0 ;
static char * last_file_name = NULL ;
static char * last_csv_file_name = NULL ;
static Latch sysLoggerLatch ;
@ -291,6 +292,13 @@ SysLoggerMain(int argc, char *argv[])
elog ( FATAL , " could not create syslogger data transfer thread: %m " ) ;
# endif /* WIN32 */
/*
* Remember active logfile ' s name . We recompute this from the reference
* time because passing down just the pg_time_t is a lot cheaper than
* passing a whole file path in the EXEC_BACKEND case .
*/
last_file_name = logfile_getname ( first_syslogger_file_time , NULL ) ;
/* remember active logfile parameters */
currentLogDir = pstrdup ( Log_directory ) ;
currentLogFilename = pstrdup ( Log_filename ) ;
@ -560,9 +568,18 @@ SysLogger_Start(void)
/*
* The initial logfile is created right in the postmaster , to verify that
* the Log_directory is writable .
* the Log_directory is writable . We save the reference time so that
* the syslogger child process can recompute this file name .
*
* It might look a bit strange to re - do this during a syslogger restart ,
* but we must do so since the postmaster closed syslogFile after the
* previous fork ( and remembering that old file wouldn ' t be right anyway ) .
* Note we always append here , we won ' t overwrite any existing file . This
* is consistent with the normal rules , because by definition this is not
* a time - based rotation .
*/
filename = logfile_getname ( time ( NULL ) , NULL ) ;
first_syslogger_file_time = time ( NULL ) ;
filename = logfile_getname ( first_syslogger_file_time , NULL ) ;
syslogFile = logfile_open ( filename , " a " , false ) ;
@ -1046,8 +1063,12 @@ pipeThread(void *arg)
# endif /* WIN32 */
/*
* o pen the csv log file - we do this opportunistically , because
* O pen the csv log file - we do this opportunistically , because
* we don ' t know if CSV logging will be wanted .
*
* This is only used the first time we open the csv log in a given syslogger
* process , not during rotations . As with opening the main log file , we
* always append in this situation .
*/
static void
open_csvlogfile ( void )
@ -1058,7 +1079,10 @@ open_csvlogfile(void)
csvlogFile = logfile_open ( filename , " a " , false ) ;
pfree ( filename ) ;
if ( last_csv_file_name ! = NULL ) /* probably shouldn't happen */
pfree ( last_csv_file_name ) ;
last_csv_file_name = filename ;
}
/*
@ -1137,14 +1161,7 @@ logfile_rotate(bool time_based_rotation, int size_rotation_for)
* 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 .
*
* For consistency , we treat CSV logs the same even though they aren ' t
* opened in the postmaster .
* Note : last_file_name should never be NULL here , but if it is , append .
*/
if ( time_based_rotation | | ( size_rotation_for & LOG_DESTINATION_STDERR ) )
{