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.
This commit is contained in:
Nick Mathewson 2019-10-17 12:48:39 -04:00
parent 3a73f6612a
commit db18ff9120
4 changed files with 37 additions and 22 deletions

View file

@ -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);
}
}

View file

@ -25,4 +25,6 @@ typedef enum {
/** How quietly should Tor log at startup? */ /** How quietly should Tor log at startup? */
extern quiet_level_t quiet_level; extern quiet_level_t quiet_level;
void add_default_log_for_quiet_level(quiet_level_t quiet);
#endif /* !defined(QUIET_LEVEL_H) */ #endif /* !defined(QUIET_LEVEL_H) */

View file

@ -109,16 +109,6 @@ static void dumpmemusage(int severity);
static void dumpstats(int severity); /* log stats */ static void dumpstats(int severity); /* log stats */
static void process_signal(int sig); 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, /** Called when we get a SIGHUP: reload configuration files and keys,
* retry all connections, and so on. */ * retry all connections, and so on. */
static int static int
@ -558,18 +548,7 @@ tor_init(int argc, char *argv[])
} }
/* give it somewhere to log to initially */ /* give it somewhere to log to initially */
switch (quiet) { add_default_log_for_quiet_level(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);
}
quiet_level = quiet; quiet_level = quiet;
{ {

View file

@ -9,6 +9,7 @@ endif
# ADD_C_FILE: INSERT SOURCES HERE. # ADD_C_FILE: INSERT SOURCES HERE.
LIBTOR_APP_A_SOURCES = \ LIBTOR_APP_A_SOURCES = \
src/app/config/config.c \ src/app/config/config.c \
src/app/config/quiet_level.c \
src/app/config/statefile.c \ src/app/config/statefile.c \
src/app/main/main.c \ src/app/main/main.c \
src/app/main/shutdown.c \ src/app/main/shutdown.c \