1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
/*-------------------------------------------------------------------------
*
* logtofile_string_format.c
* Functions to format data as strings
*
* Copyright (c) 2020-2026, Francisco Miguel Biete Banon
*
* This code is released under the PostgreSQL licence, as given at
* http://www.postgresql.org/about/licence/
*-------------------------------------------------------------------------
*/
#include "logtofile_string_format.h"
#include "logtofile_autoclose.h"
#include "logtofile_guc.h"
#include "logtofile_shmem.h"
#include "logtofile_vars.h"
#include <access/xact.h>
#include <lib/stringinfo.h>
#include <libpq/libpq-be.h>
#include <miscadmin.h>
#include <pgtime.h>
#include <port/atomics.h>
#include <postmaster/syslogger.h>
#include <storage/fd.h>
#include <storage/ipc.h>
#include <storage/lwlock.h>
#include <storage/pg_shmem.h>
#include <storage/proc.h>
#include <tcop/tcopprot.h>
#include <utils/ps_status.h>
#include <utils/timestamp.h>
#define FORMATTED_TS_LEN 64
/**
* @brief Formats the record time
* @param void
* @return void
*/
char *PgAuditLogToFile_format_now_timestamp_millis(void)
{
char *formatted_log_time;
struct pg_tm tm;
fsec_t fsec;
const char *tzn;
formatted_log_time = palloc(FORMATTED_TS_LEN);
if (timestamp2tm(GetCurrentTimestamp(), NULL, &tm, &fsec, &tzn, log_timezone) == 0)
{
pg_snprintf(formatted_log_time, FORMATTED_TS_LEN, "%04d-%02d-%02d %02d:%02d:%02d.%03d %s",
tm.tm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec,
(int)(fsec / 1000) /* milliseconds */, tzn);
}
else
{
strlcpy(formatted_log_time, "[invalid timestamp]", FORMATTED_TS_LEN);
}
return formatted_log_time;
}
|