From: Nick Mathewson Date: Thu, 17 Oct 2019 16:48:39 +0000 (-0400) Subject: Move code to add default log into quiet_level.c X-Git-Tag: tor-0.4.3.1-alpha~283^2~7 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=db18ff91208e0065c38e5f4d0dd57eb8a0ae513c;p=thirdparty%2Ftor.git 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. --- diff --git a/src/app/config/quiet_level.c b/src/app/config/quiet_level.c new file mode 100644 index 0000000000..f00d6b5a3b --- /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 quiet. */ +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 e90ec3f276..03e3f58fb0 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 e6bd4f30b2..fad2e0b62f 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 f6ae3f2b51..fb2f93d81e 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 \