Allow creating logger instances on the Wine side

So we can log filterable messages from the Wine side. Will be used to
warn about failed query interface calls.
This commit is contained in:
Robbert van der Helm
2020-12-25 15:14:30 +01:00
parent 70cb6dad89
commit cc2e12c8e4
2 changed files with 26 additions and 0 deletions
+19
View File
@@ -80,6 +80,25 @@ Logger Logger::create_from_environment(std::string prefix) {
} }
} }
Logger Logger::create_wine_stderr() {
auto env = boost::this_process::environment();
std::string verbosity =
env[logging_verbosity_environment_variable].to_string();
Verbosity verbosity_level;
try {
verbosity_level = static_cast<Verbosity>(std::stoi(verbosity));
} catch (const std::invalid_argument&) {
verbosity_level = Verbosity::basic;
}
// We're logging directly to `std::cerr` instead of to `/dev/stderr` because
// we want the STDERR redirection from the group host processes to still
// function here
return Logger(std::shared_ptr<std::ostream>(&std::cerr), verbosity_level,
"");
}
void Logger::log(const std::string& message) { void Logger::log(const std::string& message) {
const auto current_time = std::chrono::system_clock::now(); const auto current_time = std::chrono::system_clock::now();
const std::time_t timestamp = const std::time_t timestamp =
+7
View File
@@ -85,6 +85,13 @@ class Logger {
*/ */
static Logger create_from_environment(std::string prefix = ""); static Logger create_from_environment(std::string prefix = "");
/**
* Create a special logger instance that outputs directly to STDERR without
* any prefixes. This is used to be able to log filterable messages from the
* Wine side of things.
*/
static Logger create_wine_stderr();
/** /**
* Write a message to the log, prefixing it with a timestamp and this * Write a message to the log, prefixing it with a timestamp and this
* logger's prefix string. * logger's prefix string.