summaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authorparadust7 <102263465+paradust7@users.noreply.github.com>2022-05-04 11:55:01 -0700
committerGitHub <noreply@github.com>2022-05-04 20:55:01 +0200
commit0704ca055059088bdd53e15be672e6b5663b8f50 (patch)
tree26d12dc712e19fcc38e3a70ef598efc665ab0d7f /src/main.cpp
parentae7664597ed15f9ac779a9bac0595ab4125457c4 (diff)
downloadminetest-0704ca055059088bdd53e15be672e6b5663b8f50.tar.gz
minetest-0704ca055059088bdd53e15be672e6b5663b8f50.tar.bz2
minetest-0704ca055059088bdd53e15be672e6b5663b8f50.zip
Make logging cost free when there is no output target (#12247)
The logging streams now do almost no work when there is no output target for them. For example, if LL_VERBOSE has no output targets, then `verbosestream << x` will return a StreamProxy with a null target. Any further `<<` operations applied to it will do nothing.
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp16
1 files changed, 7 insertions, 9 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 5ea212d8a..ddd725134 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -453,14 +453,6 @@ static bool setup_log_params(const Settings &cmd_args)
}
}
- // If trace is enabled, enable logging of certain things
- if (cmd_args.getFlag("trace")) {
- dstream << _("Enabling trace level debug output") << std::endl;
- g_logger.setTraceEnabled(true);
- dout_con_ptr = &verbosestream; // This is somewhat old
- socket_enable_debug_output = true; // Sockets doesn't use log.h
- }
-
// In certain cases, output info level on stderr
if (cmd_args.getFlag("info") || cmd_args.getFlag("verbose") ||
cmd_args.getFlag("trace") || cmd_args.getFlag("speedtests"))
@@ -470,6 +462,12 @@ static bool setup_log_params(const Settings &cmd_args)
if (cmd_args.getFlag("verbose") || cmd_args.getFlag("trace"))
g_logger.addOutput(&stderr_output, LL_VERBOSE);
+ if (cmd_args.getFlag("trace")) {
+ dstream << _("Enabling trace level debug output") << std::endl;
+ g_logger.addOutput(&stderr_output, LL_TRACE);
+ socket_enable_debug_output = true;
+ }
+
return true;
}
@@ -599,7 +597,7 @@ static void init_log_streams(const Settings &cmd_args)
warningstream << "Deprecated use of debug_log_level with an "
"integer value; please update your configuration." << std::endl;
static const char *lev_name[] =
- {"", "error", "action", "info", "verbose"};
+ {"", "error", "action", "info", "verbose", "trace"};
int lev_i = atoi(conf_loglev.c_str());
if (lev_i < 0 || lev_i >= (int)ARRLEN(lev_name)) {
warningstream << "Supplied invalid debug_log_level!"