Created
June 2, 2017 11:24
-
-
Save kouber/89b6e5b647452a672a446b12413e20cf to your computer and use it in GitHub Desktop.
SQLog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "postgres.h" | |
#include "fmgr.h" | |
#include "utils/builtins.h" | |
#include "utils/timestamp.h" | |
#include "datatype/timestamp.h" | |
#include "postmaster/syslogger.h" | |
PG_MODULE_MAGIC; | |
static char * | |
logfile_getname(pg_time_t timestamp, const char *suffix) | |
{ | |
char *filename; | |
int len; | |
filename = palloc(MAXPGPATH); | |
snprintf(filename, MAXPGPATH, "%s/", Log_directory); | |
elog(NOTICE, "Log directory = \"%s\"", Log_directory); | |
elog(NOTICE, "Log filename = \"%s\"", Log_filename); | |
len = strlen(filename); | |
elog(NOTICE, "Length = \"%d\"", len); | |
pg_strftime(filename + len, MAXPGPATH - len, Log_filename, | |
pg_localtime(×tamp, log_timezone)); | |
elog(NOTICE, "Filename = \"%s\"", filename); | |
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; | |
} | |
PG_FUNCTION_INFO_V1(log_path); | |
Datum | |
log_path(PG_FUNCTION_ARGS) | |
{ | |
char *filename = logfile_getname(PG_GETARG_TIMESTAMP(0), ".csv"); | |
PG_RETURN_TEXT_P(cstring_to_text(filename)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment