summaryrefslogtreecommitdiff
path: root/src/include/common
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2019-05-14 14:19:49 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2019-05-14 14:20:10 -0400
commitfc9a62af3f87f4bec1e8c904ea99ae50f3c881ef (patch)
treea566ea096bbebc18e307370917e061d49f725291 /src/include/common
parentb71dad22ce8a645a47c01e544f640f35b91bfbd3 (diff)
Move logging.h and logging.c from src/fe_utils/ to src/common/.
The original placement of this module in src/fe_utils/ is ill-considered, because several src/common/ modules have dependencies on it, meaning that libpgcommon and libpgfeutils now have mutual dependencies. That makes it pointless to have distinct libraries at all. The intended design is that libpgcommon is lower-level than libpgfeutils, so only dependencies from the latter to the former are acceptable. We already have the precedent that fe_memutils and a couple of other modules in src/common/ are frontend-only, so it's not stretching anything out of whack to treat logging.c as a frontend-only module in src/common/. To the extent that such modules help provide a common frontend/backend environment for the rest of common/ to use, it's a reasonable design. (logging.c does not yet provide an ereport() emulation, but one can dream.) Hence, move these files over, and revert basically all of the build-system changes made by commit cc8d41511. There are no places that need to grow new dependencies on libpgcommon, further reinforcing the idea that this is the right solution. Discussion: https://postgr.es/m/a912ffff-f6e4-778a-c86a-cf5c47a12933@2ndquadrant.com
Diffstat (limited to 'src/include/common')
-rw-r--r--src/include/common/logging.h95
1 files changed, 95 insertions, 0 deletions
diff --git a/src/include/common/logging.h b/src/include/common/logging.h
new file mode 100644
index 00000000000..5a3249198ae
--- /dev/null
+++ b/src/include/common/logging.h
@@ -0,0 +1,95 @@
+/*-------------------------------------------------------------------------
+ * Logging framework for frontend programs
+ *
+ * Copyright (c) 2018-2019, PostgreSQL Global Development Group
+ *
+ * src/include/common/logging.h
+ *
+ *-------------------------------------------------------------------------
+ */
+#ifndef COMMON_LOGGING_H
+#define COMMON_LOGGING_H
+
+/*
+ * Log levels are informational only. They do not affect program flow.
+ */
+enum pg_log_level
+{
+ /*
+ * Not initialized yet
+ */
+ PG_LOG_NOTSET = 0,
+
+ /*
+ * Low level messages that are normally off by default.
+ */
+ PG_LOG_DEBUG,
+
+ /*
+ * Any program messages that go to stderr, shown by default. (The
+ * program's normal output should go to stdout and not use the logging
+ * system.)
+ */
+ PG_LOG_INFO,
+
+ /*
+ * Warnings and "almost" errors, depends on the program
+ */
+ PG_LOG_WARNING,
+
+ /*
+ * Errors
+ */
+ PG_LOG_ERROR,
+
+ /*
+ * Severe errors that cause program termination. (One-shot programs may
+ * chose to label even fatal errors as merely "errors". The distinction
+ * is up to the program.)
+ */
+ PG_LOG_FATAL,
+
+ /*
+ * Turn all logging off.
+ */
+ PG_LOG_OFF,
+};
+
+extern enum pg_log_level __pg_log_level;
+
+/*
+ * Kind of a hack to be able to produce the psql output exactly as required by
+ * the regression tests.
+ */
+#define PG_LOG_FLAG_TERSE 1
+
+void pg_logging_init(const char *argv0);
+void pg_logging_config(int new_flags);
+void pg_logging_set_level(enum pg_log_level new_level);
+void pg_logging_set_pre_callback(void (*cb)(void));
+void pg_logging_set_locus_callback(void (*cb)(const char **filename, uint64 *lineno));
+
+void pg_log_generic(enum pg_log_level level, const char * pg_restrict fmt, ...) pg_attribute_printf(2, 3);
+void pg_log_generic_v(enum pg_log_level level, const char * pg_restrict fmt, va_list ap) pg_attribute_printf(2, 0);
+
+#define pg_log_fatal(...) do { \
+ if (likely(__pg_log_level <= PG_LOG_FATAL)) pg_log_generic(PG_LOG_FATAL, __VA_ARGS__); \
+ } while(0)
+
+#define pg_log_error(...) do { \
+ if (likely(__pg_log_level <= PG_LOG_ERROR)) pg_log_generic(PG_LOG_ERROR, __VA_ARGS__); \
+ } while(0)
+
+#define pg_log_warning(...) do { \
+ if (likely(__pg_log_level <= PG_LOG_WARNING)) pg_log_generic(PG_LOG_WARNING, __VA_ARGS__); \
+ } while(0)
+
+#define pg_log_info(...) do { \
+ if (likely(__pg_log_level <= PG_LOG_INFO)) pg_log_generic(PG_LOG_INFO, __VA_ARGS__); \
+ } while(0)
+
+#define pg_log_debug(...) do { \
+ if (unlikely(__pg_log_level <= PG_LOG_DEBUG)) pg_log_generic(PG_LOG_DEBUG, __VA_ARGS__); \
+ } while(0)
+
+#endif /* COMMON_LOGGING_H */