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