sssd/0017-UTIL-Add-wrapper-function-to-configure-logger.patch

133 lines
4.0 KiB
Diff
Raw Normal View History

From dad79765d9ccafb3ba5d31a20462d73af96fa058 Mon Sep 17 00:00:00 2001
From: Lukas Slebodnik <lslebodn@redhat.com>
Date: Mon, 23 Oct 2017 14:58:14 +0200
Subject: [PATCH 17/79] UTIL: Add wrapper function to configure logger
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Let's use one enum for logger type instead of many integers (debug_to_file,
debug_to_stderr plus some weird combination for journald).
Old variable were also transformed to enum for backward compatibility
Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
---
src/util/debug.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/util/debug.h | 18 ++++++++++++++++++
2 files changed, 72 insertions(+)
diff --git a/src/util/debug.c b/src/util/debug.c
index ca4fa4c6f5b150700a0a136d8a7ca9df30c29d73..4e469447e5ab8aa89cd57bcd6d00269875a12bc6 100644
--- a/src/util/debug.c
+++ b/src/util/debug.c
@@ -43,9 +43,63 @@ int debug_timestamps = SSSDBG_TIMESTAMP_UNRESOLVED;
int debug_microseconds = SSSDBG_MICROSECONDS_UNRESOLVED;
int debug_to_file = 0;
int debug_to_stderr = 0;
+enum sss_logger_t sss_logger;
const char *debug_log_file = "sssd";
FILE *debug_file = NULL;
+const char *sss_logger_str[] = {
+ [STDERR_LOGGER] = "stderr",
+ [FILES_LOGGER] = "files",
+#ifdef WITH_JOURNALD
+ [JOURNALD_LOGGER] = "journald",
+#endif
+ NULL,
+};
+
+#ifdef WITH_JOURNALD
+#define JOURNALD_STR " journald,"
+#else
+#define JOURNALD_STR ""
+#endif
+
+void sss_set_logger(const char *logger)
+{
+ /* use old flags */
+ if (logger == NULL) {
+ if (debug_to_stderr != 0) {
+ sss_logger = STDERR_LOGGER;
+ }
+ /* It is never described what should be used in case of
+ * debug_to_stderr == 1 && debug_to_file == 1. Because neither
+ * of binaries provide both command line arguments.
+ * Let files have higher priority.
+ */
+ if (debug_to_file != 0) {
+ sss_logger = FILES_LOGGER;
+ }
+#ifdef WITH_JOURNALD
+ if (debug_to_file == 0 && debug_to_stderr == 0) {
+ sss_logger = JOURNALD_LOGGER;
+ }
+#endif
+ } else {
+ if (strcmp(logger, "stderr") == 0) {
+ sss_logger = STDERR_LOGGER;
+ } else if (strcmp(logger, "files") == 0) {
+ sss_logger = FILES_LOGGER;
+#ifdef WITH_JOURNALD
+ } else if (strcmp(logger, "journald") == 0) {
+ sss_logger = JOURNALD_LOGGER;
+#endif
+ } else {
+ /* unexpected value */
+ fprintf(stderr, "Unexpected logger: %s\nExpected:%s stderr, "
+ "files\n", logger, JOURNALD_STR);
+ sss_logger = STDERR_LOGGER;
+ }
+ }
+}
+
errno_t set_debug_file_from_fd(const int fd)
{
FILE *dummy;
diff --git a/src/util/debug.h b/src/util/debug.h
index 2a1bd4ffd30817d7128805996c21105fe40982a2..4adafb7cfc03f7381c4d03071eb44edad04bee00 100644
--- a/src/util/debug.h
+++ b/src/util/debug.h
@@ -31,13 +31,26 @@
#define APPEND_LINE_FEED 0x1
+enum sss_logger_t {
+ STDERR_LOGGER = 0,
+ FILES_LOGGER,
+#ifdef WITH_JOURNALD
+ JOURNALD_LOGGER,
+#endif
+};
+
+extern const char *sss_logger_str[];
extern const char *debug_prg_name;
extern int debug_level;
extern int debug_timestamps;
extern int debug_microseconds;
extern int debug_to_file;
extern int debug_to_stderr;
+extern enum sss_logger_t sss_logger;
extern const char *debug_log_file;
+
+void sss_set_logger(const char *logger);
+
void sss_vdebug_fn(const char *file,
long line,
const char *function,
@@ -80,6 +93,11 @@ int get_fd_from_debug_file(void);
#define SSSDBG_MICROSECONDS_UNRESOLVED -1
#define SSSDBG_MICROSECONDS_DEFAULT 0
+#define SSSD_LOGGER_OPTS \
+ {"logger", '\0', POPT_ARG_STRING, &opt_logger, 0, \
+ _("Set logger"), "stderr|files|journald"},
+
+
#define SSSD_DEBUG_OPTS \
{"debug-level", 'd', POPT_ARG_INT, &debug_level, 0, \
_("Debug level"), NULL}, \
--
2.15.1