コード例 #1
0
/*
 * construct logfile name using timestamp information
 *
 * Result is palloc'd.
 */
static char *
logfile_getname(pg_time_t timestamp)
{
	char	   *filename;
	int			len;
	struct pg_tm *tm;

	filename = palloc(MAXPGPATH);

	if (is_absolute_path(Log_directory))
		snprintf(filename, MAXPGPATH, "%s/", Log_directory);
	else
		snprintf(filename, MAXPGPATH, "%s/%s/", DataDir, Log_directory);

	len = strlen(filename);

	if (strchr(Log_filename, '%'))
	{
		/* treat it as a strftime pattern */
		tm = pg_localtime(&timestamp);
		pg_strftime(filename + len, MAXPGPATH - len, Log_filename, tm);
	}
	else 
	{
		/* no strftime escapes, so append timestamp to new filename */
		snprintf(filename + len, MAXPGPATH - len, "%s.%lu",
				 Log_filename, (unsigned long) timestamp);
	}

	return filename;
}
コード例 #2
0
ファイル: syslogger.c プロジェクト: markwkm/postgres
/*
 * construct logfile name using timestamp information
 *
 * If suffix isn't NULL, append it to the name, replacing any ".log"
 * that may be in the pattern.
 *
 * Result is palloc'd.
 */
static char *
logfile_getname(pg_time_t timestamp, const char *suffix)
{
	char	   *filename;
	int			len;

	filename = palloc(MAXPGPATH);

	snprintf(filename, MAXPGPATH, "%s/", Log_directory);

	len = strlen(filename);

	/* treat Log_filename as a strftime pattern */
	pg_strftime(filename + len, MAXPGPATH - len, Log_filename,
				pg_localtime(&timestamp, log_timezone));

	if (suffix != NULL)
	{
		len = strlen(filename);
		if (len > 4 && (strcmp(filename + (len - 4), ".log") == 0))
			len -= 4;
		strlcpy(filename + len, suffix, MAXPGPATH - len);
	}

	return filename;
}
コード例 #3
0
static void
reCacheBackendStartTime(void)
{
	pg_time_t	stampTime = (pg_time_t) MyStartTime;

	/*
	 * Note: we expect that guc.c will ensure that log_timezone is set up (at
	 * least with a minimal GMT value) before Log_line_prefix can become
	 * nonempty or CSV mode can be selected.
	 */
	pg_strftime(cachedBackendStartTime, FORMATTED_TS_LEN,
				"%Y-%m-%d %H:%M:%S %Z",
				pg_localtime(&stampTime, log_timezone));
}
コード例 #4
0
ファイル: nabstime.c プロジェクト: GisKook/Gis
/*
 * timeofday -
 *	   returns the current time as a text. similar to timenow() but returns
 *	   seconds with more precision (up to microsecs). (I need this to compare
 *	   the Wisconsin benchmark with Illustra whose TimeNow() shows current
 *	   time with precision up to microsecs.)			  - ay 3/95
 */
Datum
timeofday(PG_FUNCTION_ARGS)
{
	struct timeval tp;
	char		templ[128];
	char		buf[128];
	pg_time_t	tt;

	gettimeofday(&tp, NULL);
	tt = (pg_time_t) tp.tv_sec;
	pg_strftime(templ, sizeof(templ), "%a %b %d %H:%M:%S.%%06d %Y %Z",
				pg_localtime(&tt, session_timezone));
	snprintf(buf, sizeof(buf), templ, tp.tv_usec);

	PG_RETURN_TEXT_P(cstring_to_text(buf));
}
コード例 #5
0
ファイル: redislog.c プロジェクト: mbeccati/redislog
/*
 * setup formatted_start_time
 * (taken from backend/utils/error/elog.c)
 */
static void
setup_formatted_start_time(void)
{
	pg_time_t	stamp_time = (pg_time_t) MyStartTime;

	/*
	 * Note: we expect that guc.c will ensure that log_timezone is set up (at
	 * least with a minimal GMT value) before Log_line_prefix can become
	 * nonempty or CSV mode can be selected.
	 *
	 * Note: we don't have the exact millisecond here.
	 */
	pg_strftime(formatted_start_time, LOG_TIMESTAMP_LEN,
				"%Y-%m-%dT%H:%M:%S%z",
				pg_localtime(&stamp_time, log_timezone));
}
コード例 #6
0
ファイル: cdbfts.c プロジェクト: BALDELab/incubator-hawq
static void
QDMirroringFormatTime(char *logTimeStr, int logTimeStrMax,
							  struct timeval *lastLogTimeVal)
{
	pg_time_t stamp_time = (pg_time_t) lastLogTimeVal->tv_sec;
	pg_tz	   *tz;

	/*
	 * The following code is copied from log_line_prefix.
	 */
	tz = log_timezone ? log_timezone : gmt_timezone;

	pg_strftime(logTimeStr, logTimeStrMax,
				"%Y-%m-%d %H:%M:%S %Z",
				pg_localtime(&stamp_time, tz));

}
コード例 #7
0
static void
formatLogTime(char *dst, size_t dstSz, struct timeval tv)
{
	char				 msbuf[8];
	struct pg_tm		*tm;
	pg_time_t			 stamp_time;

	stamp_time = (pg_time_t) tv.tv_sec;
	tm = pg_localtime(&stamp_time, log_timezone);

	Assert(dstSz >= FORMATTED_TS_LEN);
	pg_strftime(dst, dstSz,
				/* leave room for milliseconds... */
				"%Y-%m-%d %H:%M:%S     %Z", tm);

	/* 'paste' milliseconds into place... */
	sprintf(msbuf, ".%03d", (int) (tv.tv_usec / 1000));
	strncpy(dst + 19, msbuf, 4);
}
コード例 #8
0
ファイル: jsonlog.c プロジェクト: fabriziomello/pg_plugins
static void
setup_formatted_log_time(void)
{
	struct timeval tv;
	pg_time_t   stamp_time;
	char		msbuf[8];

	gettimeofday(&tv, NULL);
	stamp_time = (pg_time_t) tv.tv_sec;

	/*
	 * Note: we ignore log_timezone as JSON is meant to be
	 * machine-readable so load arbitrarily UTC. Users can use tools to
	 * display the timestamps in their local time zone. jq in particular
	 * can only handle timestamps with the iso-8601 "Z" suffix
	 * representing UTC.
	 *
	 * Note that JSON does not specify the format of dates and
	 * timestamps, however Javascript enforces a somewhat-widely spread
	 * format like what is done in Date's toJSON. The main reasons to
	 * do so are that this is conform to ISO 8601 and that this is
	 * rather established.
	 *
	 * Take care to leave room for milliseconds which we paste in.
	 */

	/* Load timezone only once */
	if (!utc_tz)
		utc_tz = pg_tzset("UTC");

	pg_strftime(formatted_log_time, FORMATTED_TS_LEN,
				"%Y-%m-%dT%H:%M:%S.000Z",
				pg_localtime(&stamp_time, utc_tz));

	/* 'paste' milliseconds into place... */
	sprintf(msbuf, ".%03d", (int) (tv.tv_usec / 1000));
	memcpy(formatted_log_time + 19, msbuf, 4);
}
コード例 #9
0
ファイル: jsonlog.c プロジェクト: harry-2016/pg_plugins
static void
setup_formatted_log_time(void)
{
	struct timeval tv;
	pg_time_t   stamp_time;
	char		msbuf[8];

	gettimeofday(&tv, NULL);
	stamp_time = (pg_time_t) tv.tv_sec;

	/*
	 * Note: we expect that guc.c will ensure that log_timezone is set up (at
	 * least with a minimal GMT value) before Log_line_prefix can become
	 * nonempty or CSV mode can be selected.
	 */
	pg_strftime(log_time, LOG_TIMESTAMP_LEN,
				/* leave room for milliseconds... */
				"%Y-%m-%d %H:%M:%S	 %Z",
				pg_localtime(&stamp_time, log_timezone));

	/* 'paste' milliseconds into place... */
	sprintf(msbuf, ".%03d", (int) (tv.tv_usec / 1000));
	strncpy(log_time + 19, msbuf, 4);
}