2004-08-06 01:32:13 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* syslogger.h
|
|
|
|
* Exports from postmaster/syslogger.c.
|
|
|
|
*
|
2024-01-04 02:49:05 +01:00
|
|
|
* Copyright (c) 2004-2024, PostgreSQL Global Development Group
|
2004-08-06 01:32:13 +02:00
|
|
|
*
|
2010-09-20 22:08:53 +02:00
|
|
|
* src/include/postmaster/syslogger.h
|
2004-08-06 01:32:13 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#ifndef _SYSLOGGER_H
|
|
|
|
#define _SYSLOGGER_H
|
|
|
|
|
2007-06-14 03:48:51 +02:00
|
|
|
#include <limits.h> /* for PIPE_BUF */
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Primitive protocol structure for writing to syslogger pipe(s). The idea
|
|
|
|
* here is to divide long messages into chunks that are not more than
|
|
|
|
* PIPE_BUF bytes long, which according to POSIX spec must be written into
|
|
|
|
* the pipe atomically. The pipe reader then uses the protocol headers to
|
|
|
|
* reassemble the parts of a message into a single string. The reader can
|
|
|
|
* also cope with non-protocol data coming down the pipe, though we cannot
|
|
|
|
* guarantee long strings won't get split apart.
|
|
|
|
*
|
2007-08-19 03:41:25 +02:00
|
|
|
* We use non-nul bytes in is_last to make the protocol a tiny bit
|
|
|
|
* more robust against finding a false double nul byte prologue. But
|
|
|
|
* we still might find it in the len and/or pid bytes unless we're careful.
|
2007-06-14 03:48:51 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef PIPE_BUF
|
|
|
|
/* Are there any systems with PIPE_BUF > 64K? Unlikely, but ... */
|
|
|
|
#if PIPE_BUF > 65536
|
|
|
|
#define PIPE_CHUNK_SIZE 65536
|
|
|
|
#else
|
|
|
|
#define PIPE_CHUNK_SIZE ((int) PIPE_BUF)
|
|
|
|
#endif
|
|
|
|
#else /* not defined */
|
|
|
|
/* POSIX says the value of PIPE_BUF must be at least 512, so use that */
|
|
|
|
#define PIPE_CHUNK_SIZE 512
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
char nuls[2]; /* always \0\0 */
|
|
|
|
uint16 len; /* size of this chunk (counts data only) */
|
|
|
|
int32 pid; /* writer's pid */
|
2021-09-13 02:03:45 +02:00
|
|
|
bits8 flags; /* bitmask of PIPE_PROTO_* */
|
2015-02-20 06:11:42 +01:00
|
|
|
char data[FLEXIBLE_ARRAY_MEMBER]; /* data payload starts here */
|
2007-06-14 03:48:51 +02:00
|
|
|
} PipeProtoHeader;
|
|
|
|
|
|
|
|
typedef union
|
|
|
|
{
|
|
|
|
PipeProtoHeader proto;
|
|
|
|
char filler[PIPE_CHUNK_SIZE];
|
|
|
|
} PipeProtoChunk;
|
|
|
|
|
|
|
|
#define PIPE_HEADER_SIZE offsetof(PipeProtoHeader, data)
|
|
|
|
#define PIPE_MAX_PAYLOAD ((int) (PIPE_CHUNK_SIZE - PIPE_HEADER_SIZE))
|
|
|
|
|
2021-09-13 02:03:45 +02:00
|
|
|
/* flag bits for PipeProtoHeader->flags */
|
|
|
|
#define PIPE_PROTO_IS_LAST 0x01 /* last chunk of message? */
|
|
|
|
/* log destinations */
|
|
|
|
#define PIPE_PROTO_DEST_STDERR 0x10
|
|
|
|
#define PIPE_PROTO_DEST_CSVLOG 0x20
|
Introduce log_destination=jsonlog
"jsonlog" is a new value that can be added to log_destination to provide
logs in the JSON format, with its output written to a file, making it
the third type of destination of this kind, after "stderr" and
"csvlog". The format is convenient to feed logs to other applications.
There is also a plugin external to core that provided this feature using
the hook in elog.c, but this had to overwrite the output of "stderr" to
work, so being able to do both at the same time was not possible. The
files generated by this log format are suffixed with ".json", and use
the same rotation policies as the other two formats depending on the
backend configuration.
This takes advantage of the refactoring work done previously in ac7c807,
bed6ed3, 8b76f89 and 2d77d83 for the backend parts, and 72b76f7 for the
TAP tests, making the addition of any new file-based format rather
straight-forward.
The documentation is updated to list all the keys and the values that
can exist in this new format. pg_current_logfile() also required a
refresh for the new option.
Author: Sehrope Sarkuni, Michael Paquier
Reviewed-by: Nathan Bossart, Justin Pryzby
Discussion: https://postgr.es/m/CAH7T-aqswBM6JWe4pDehi1uOiufqe06DJWaU5=X7dDLyqUExHg@mail.gmail.com
2022-01-17 02:16:53 +01:00
|
|
|
#define PIPE_PROTO_DEST_JSONLOG 0x40
|
2007-06-14 03:48:51 +02:00
|
|
|
|
2004-08-06 01:32:13 +02:00
|
|
|
/* GUC options */
|
2022-04-08 14:16:38 +02:00
|
|
|
extern PGDLLIMPORT bool Logging_collector;
|
|
|
|
extern PGDLLIMPORT int Log_RotationAge;
|
|
|
|
extern PGDLLIMPORT int Log_RotationSize;
|
2007-07-25 14:22:54 +02:00
|
|
|
extern PGDLLIMPORT char *Log_directory;
|
|
|
|
extern PGDLLIMPORT char *Log_filename;
|
2022-04-08 14:16:38 +02:00
|
|
|
extern PGDLLIMPORT bool Log_truncate_on_rotation;
|
|
|
|
extern PGDLLIMPORT int Log_file_mode;
|
2004-08-06 01:32:13 +02:00
|
|
|
|
|
|
|
#ifndef WIN32
|
2022-04-08 14:16:38 +02:00
|
|
|
extern PGDLLIMPORT int syslogPipe[2];
|
2004-08-06 01:32:13 +02:00
|
|
|
#else
|
2022-04-08 14:16:38 +02:00
|
|
|
extern PGDLLIMPORT HANDLE syslogPipe[2];
|
2004-08-06 01:32:13 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
extern int SysLogger_Start(void);
|
|
|
|
|
2022-09-20 22:09:30 +02:00
|
|
|
extern void write_syslogger_file(const char *buffer, int count, int destination);
|
2004-08-06 01:32:13 +02:00
|
|
|
|
2024-03-18 10:35:08 +01:00
|
|
|
extern void SysLoggerMain(char *startup_data, size_t startup_data_len) pg_attribute_noreturn();
|
2004-08-06 01:32:13 +02:00
|
|
|
|
2018-09-01 18:46:49 +02:00
|
|
|
extern bool CheckLogrotateSignal(void);
|
|
|
|
extern void RemoveLogrotateSignalFiles(void);
|
|
|
|
|
2017-03-03 07:02:45 +01:00
|
|
|
/*
|
|
|
|
* Name of files saving meta-data information about the log
|
|
|
|
* files currently in use by the syslogger
|
|
|
|
*/
|
|
|
|
#define LOG_METAINFO_DATAFILE "current_logfiles"
|
|
|
|
#define LOG_METAINFO_DATAFILE_TMP LOG_METAINFO_DATAFILE ".tmp"
|
|
|
|
|
2004-08-06 01:32:13 +02:00
|
|
|
#endif /* _SYSLOGGER_H */
|