[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor/master] Move code to add default log into quiet_level.c
commit db18ff91208e0065c38e5f4d0dd57eb8a0ae513c
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date: Thu Oct 17 12:48:39 2019 -0400
Move code to add default log into quiet_level.c
I'm about to unify the code for handling this between main.c and
config.c.
---
src/app/config/quiet_level.c | 33 +++++++++++++++++++++++++++++++++
src/app/config/quiet_level.h | 2 ++
src/app/main/main.c | 23 +----------------------
src/core/include.am | 1 +
4 files changed, 37 insertions(+), 22 deletions(-)
diff --git a/src/app/config/quiet_level.c b/src/app/config/quiet_level.c
new file mode 100644
index 000000000..f00d6b5a3
--- /dev/null
+++ b/src/app/config/quiet_level.c
@@ -0,0 +1,33 @@
+/* Copyright (c) 2001 Matej Pfajfar.
+ * Copyright (c) 2001-2004, Roger Dingledine.
+ * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
+ * Copyright (c) 2007-2019, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+#include "orconfig.h"
+#include "lib/log/log.h"
+#include "app/config/quiet_level.h"
+
+/** Decides our behavior when no logs are configured/before any logs have been
+ * configured. For QUIET_NONE, we log notice to stdout as normal. For
+ * QUIET_HUSH, we log warnings only. For QUIET_SILENT, we log nothing.
+ */
+quiet_level_t quiet_level = 0;
+
+/** Add a default log (or not), depending on the value of <b>quiet</b>. */
+void
+add_default_log_for_quiet_level(quiet_level_t quiet)
+{
+ switch (quiet) {
+ case QUIET_SILENT:
+ /* --quiet: no initial logging */
+ return;
+ case QUIET_HUSH:
+ /* --hush: log at warning or higher. */
+ add_default_log(LOG_WARN);
+ break;
+ case QUIET_NONE: /* fall through */
+ default:
+ add_default_log(LOG_NOTICE);
+ }
+}
diff --git a/src/app/config/quiet_level.h b/src/app/config/quiet_level.h
index e90ec3f27..03e3f58fb 100644
--- a/src/app/config/quiet_level.h
+++ b/src/app/config/quiet_level.h
@@ -25,4 +25,6 @@ typedef enum {
/** How quietly should Tor log at startup? */
extern quiet_level_t quiet_level;
+void add_default_log_for_quiet_level(quiet_level_t quiet);
+
#endif /* !defined(QUIET_LEVEL_H) */
diff --git a/src/app/main/main.c b/src/app/main/main.c
index e6bd4f30b..fad2e0b62 100644
--- a/src/app/main/main.c
+++ b/src/app/main/main.c
@@ -109,16 +109,6 @@ static void dumpmemusage(int severity);
static void dumpstats(int severity); /* log stats */
static void process_signal(int sig);
-/********* START VARIABLES **********/
-
-/** Decides our behavior when no logs are configured/before any logs have been
- * configured. For QUIET_NONE, we log notice to stdout as normal. For
- * QUIET_HUSH, we log warnings only. For QUIET_SILENT, we log nothing.
- */
-quiet_level_t quiet_level = 0;
-
-/********* END VARIABLES ************/
-
/** Called when we get a SIGHUP: reload configuration files and keys,
* retry all connections, and so on. */
static int
@@ -558,18 +548,7 @@ tor_init(int argc, char *argv[])
}
/* give it somewhere to log to initially */
- switch (quiet) {
- case QUIET_SILENT:
- /* --quiet: no initial logging */
- break;
- case QUIET_HUSH:
- /* --hush: log at warning or higher. */
- add_default_log(LOG_WARN);
- break;
- case QUIET_NONE: /* fall through */
- default:
- add_default_log(LOG_NOTICE);
- }
+ add_default_log_for_quiet_level(quiet);
quiet_level = quiet;
{
diff --git a/src/core/include.am b/src/core/include.am
index f6ae3f2b5..fb2f93d81 100644
--- a/src/core/include.am
+++ b/src/core/include.am
@@ -9,6 +9,7 @@ endif
# ADD_C_FILE: INSERT SOURCES HERE.
LIBTOR_APP_A_SOURCES = \
src/app/config/config.c \
+ src/app/config/quiet_level.c \
src/app/config/statefile.c \
src/app/main/main.c \
src/app/main/shutdown.c \
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits