Create a persistent install log file to help root cause package upgrade issues#13500
Create a persistent install log file to help root cause package upgrade issues#13500
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds persistent install logging functionality to help diagnose WSL package upgrade issues by creating a log file at C:\Windows\temp\wsl-install-log.txt.
Key changes:
- Implements
WriteInstallLog()function to write timestamped log entries to a persistent file - Modifies
IsUpdateNeeded()to return both update status and existing version information - Adds logging calls throughout the MSI installation process to track upgrade operations
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
src/windows/wslinstaller/exe/WslInstaller.cpp |
Modified IsUpdateNeeded() to return version info and added install logging call |
src/windows/wslinstall/wslinstall.def |
Added new WslFinalizeInstallation export |
src/windows/wslinstall/DllMain.cpp |
Added logging calls to MSI installation functions and new finalize function |
src/windows/common/wslutil.h |
Added WriteInstallLog() function declaration |
src/windows/common/wslutil.cpp |
Implemented WriteInstallLog() function with file handling and mutex synchronization |
msipackage/package.wix.in |
Added custom action for install finalization |
| auto logLine = std::format("{:%FT%TZ} {}[{}]: {}\n", std::chrono::system_clock::now(), processName, WSL_PACKAGE_VERSION, Content); | ||
|
|
||
| DWORD bytesWritten{}; | ||
| THROW_IF_WIN32_BOOL_FALSE(WriteFile(file.get(), logLine.c_str(), static_cast<DWORD>(logLine.size()), &bytesWritten, nullptr)); |
There was a problem hiding this comment.
Using c_str() on a std::string to write to a file will only write the string content without accounting for UTF-8 encoding. Since the log line contains UTF-8 formatted timestamps and potentially non-ASCII characters, this should use logLine.data() and logLine.length() to ensure proper byte handling.
| THROW_IF_WIN32_BOOL_FALSE(WriteFile(file.get(), logLine.c_str(), static_cast<DWORD>(logLine.size()), &bytesWritten, nullptr)); | |
| THROW_IF_WIN32_BOOL_FALSE(WriteFile(file.get(), logLine.data(), static_cast<DWORD>(logLine.size()), &bytesWritten, nullptr)); |
| const auto key = OpenLxssMachineKey(KEY_READ); | ||
| const auto productCode = ReadString(key.get(), L"Msi", L"ProductCode", nullptr); | ||
|
|
||
| WriteInstallLog(std::format("Uninstalling MSI package: {}", productCode)); |
There was a problem hiding this comment.
Type mismatch in format string. productCode is a std::wstring (wide string) but the format string expects a narrow string. This should either convert productCode to narrow string or use a wide string format approach.
| WriteInstallLog(std::format("Uninstalling MSI package: {}", productCode)); | |
| WriteInstallLog(std::format(L"Uninstalling MSI package: {}", productCode)); |
There was a problem hiding this comment.
does std::format handle this?
There was a problem hiding this comment.
It does because we made it ! We have custom std::formatters to do this for us: https://github.com/microsoft/WSL/blob/332efe1a8dfdcb3d18a2d37e195cdec014f7d43f/src/shared/inc/stringshared.h#L806C1-L807C1
|
|
||
| if (type == INSTALLMESSAGE_ERROR || type == INSTALLMESSAGE_FATALEXIT || type == INSTALLMESSAGE_WARNING) | ||
| { | ||
| WriteInstallLog(std::format("MSI message: {}", message)); |
There was a problem hiding this comment.
Type mismatch in format string. The message parameter is LPCWSTR (wide string) but std::format in this context expects a narrow string. This will cause compilation errors or incorrect output.
| WriteInstallLog(std::format("MSI message: {}", message)); | |
| WriteInstallLog(std::format(L"MSI message: {}", std::wstring_view(message))); |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…
Summary of the Pull Request
This change adds logic to write various package installation loglines to
C:\Windows\temp\wsl-install-log.txt, which should help us root cause #11013PR Checklist
Detailed Description of the Pull Request / Additional comments
Validation Steps Performed