add a command line option for disabling log sanitization (#8505)

This commit is contained in:
Subhraman Sarkar 2024-07-09 22:07:07 +05:30 committed by Steve Cotton
parent 5461f226e7
commit 8166ab25ab
4 changed files with 17 additions and 0 deletions

View file

@ -239,6 +239,7 @@ commandline_options::commandline_options(const std::vector<std::string>& args)
("log-precise", "shows the timestamps in log output with more precision.")
("no-log-to-file", "log output is written only to standard error rather than to a file. The environment variable WESNOTH_NO_LOG_FILE can also be set as an alternative.")
("log-to-file", "log output is written to a file. Cancels the effect of --no-log-to-file whether implicit or explicit.")
("no-log-sanitize", "do not sanitize usernames in log")
("wnoconsole", "For Windows, when used with --no-log-to-file, results in output being written to cerr/cout instead of CONOUT. Otherwise, does nothing.")
;

View file

@ -59,6 +59,8 @@ static bool timestamp = true;
static bool precise_timestamp = false;
static std::mutex log_mutex;
static bool log_sanitization = true;
/** whether the current logs directory is writable */
static std::optional<bool> is_log_dir_writable_ = std::nullopt;
/** alternative stream to write data to */
@ -432,9 +434,16 @@ static void print_precise_timestamp(std::ostream& out) noexcept
} catch(...) {}
}
void set_log_sanitize(bool sanitize) {
log_sanitization = sanitize;
}
std::string sanitize_log(const std::string& logstr)
{
std::string str = logstr;
if (!log_sanitization) {
return logstr;
}
#ifdef _WIN32
const char* user_name = getenv("USERNAME");

View file

@ -137,6 +137,9 @@ void set_strict_severity(severity severity);
void set_strict_severity(const logger &lg);
bool broke_strict();
/** toggle log sanitization */
void set_log_sanitize(bool sanitize);
/**
* Do the initial redirection to a log file if the logs directory is writable.
* Also performs log rotation to delete old logs.

View file

@ -968,6 +968,10 @@ int main(int argc, char** argv)
} else if(arg == "--log-to-file") {
write_to_log_file = true;
}
if(arg == "--no-log-sanitize") {
lg::set_log_sanitize(false);
}
if(arg == "--wnoconsole") {
no_con = true;