mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-11 17:51:04 +00:00
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.
This commit is contained in:
parent
ae7664597e
commit
0704ca0550
14 changed files with 336 additions and 192 deletions
16
src/main.cpp
16
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!"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue