diff --git a/src/common/logging/common.cpp b/src/common/logging/common.cpp index 55ba54e7..152868f2 100644 --- a/src/common/logging/common.cpp +++ b/src/common/logging/common.cpp @@ -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(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::cerr), verbosity_level, + ""); +} + void Logger::log(const std::string& message) { const auto current_time = std::chrono::system_clock::now(); const std::time_t timestamp = diff --git a/src/common/logging/common.h b/src/common/logging/common.h index c26ecc8f..3f10abdc 100644 --- a/src/common/logging/common.h +++ b/src/common/logging/common.h @@ -85,6 +85,13 @@ class Logger { */ 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 * logger's prefix string.