-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathlogger.h
144 lines (121 loc) · 3.03 KB
/
logger.h
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*----------------------------------------------------------------------------
*
* logger.h
* GUC-controlled map from application meaningful log tags to actual log
* levels.
*
* Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
* Portions Copyright (c) 2021, Postgres Professional
*
*----------------------------------------------------------------------------
*/
#include "postgres.h"
#include "postmaster/bgworker.h"
#include "utils/elog.h"
#include "utils/memutils.h"
/*
* this hack allows to use mtm_log with direct log level (e.g. ERROR), see
* mtm_log
*/
#define FIRST_UNUSED_ERRCODE (PANIC + 1)
/* keep it in sync with mtm_log_gucs */
typedef enum MtmLogTag
{
/* general */
MtmTxTrace = FIRST_UNUSED_ERRCODE,
MtmTxFinish,
/* coordinator */
MtmCoordinatorTrace,
/* dmq */
DmqStateIntermediate,
DmqStateFinal,
DmqTraceOutgoing,
DmqTraceIncoming,
DmqTraceShmMq,
DmqPqTiming,
/* resolver */
ResolverState,
ResolverTx,
ResolverTasks,
/* status worker */
StatusRequest,
/* pool */
BgwPoolEvent,
BgwPoolEventDebug,
/* ddd */
DeadlockCheck,
DeadlockUpdate,
DeadlockSerialize,
/* ddl */
DDLStmtOutgoing,
DDLStmtIncoming,
DDLProcessingTrace,
/* walsender's proto */
ProtoTraceFilter,
ProtoTraceSender,
ProtoTraceMessage,
ProtoTraceState,
/* receiver */
MtmReceiverState,
MtmReceiverStateDebug,
MtmReceiverFilter,
MtmApplyMessage,
MtmApplyTrace,
MtmApplyError,
MtmApplyBgwFinish,
MtmReceiverFeedback,
/* state */
MtmStateMessage,
MtmStateSwitch,
MtmStateDebug,
/* syncpoints */
SyncpointCreated,
SyncpointApply,
/* Node add/drop */
NodeMgmt
} MtmLogTag;
typedef struct MtmLogGuc
{
const char *name;
int default_val;
int val;
} MtmLogGuc;
extern MtmLogGuc mtm_log_gucs[];
#define MTM_TAG "[MTM]%s"
/*
* I tried to use get_ps_display instead of MyBgworkerEntry, but it returns
* only dynamic 'activity' part which doesn't include bgw name. Apparently
* there is no way to retrieve main part. Weird.
*/
extern bool MtmBackgroundWorker; /* avoid including multimaster.h for this */
extern char *walsender_name; /* same for pglogical_proto.h */
static inline char *
am(void)
{
char *res = " ";
char *name = NULL;
if (MtmBackgroundWorker)
name = MyBgworkerEntry->bgw_name;
else if (walsender_name)
name = walsender_name;
if (name)
{
/* this is for elog, so alloc in ErrorContext where fmt is evaluated */
MemoryContext old_ctx = MemoryContextSwitchTo(ErrorContext);
res = psprintf(" [%s] ", name);
MemoryContextSwitchTo(old_ctx);
}
return res;
}
#define MTM_ERRMSG(fmt,...) errmsg(MTM_TAG fmt, am(), ## __VA_ARGS__)
/*
* tag can either one of MtmLogTag values (in which case corresponding GUC
* defines the actual log level) or direct level like ERROR
*/
#define mtm_log(tag, fmt, ...) ereport( \
((tag) >= FIRST_UNUSED_ERRCODE ? \
mtm_log_gucs[tag - FIRST_UNUSED_ERRCODE].val : (tag)), \
(errmsg(MTM_TAG fmt, \
am(), ## __VA_ARGS__), \
errhidestmt(true), errhidecontext(true)))