-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Create a persistent install log file to help root cause package upgrade issues #13500
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)); |
Copilot
AI
Sep 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)); |
Copilot
AI
Sep 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does std::format handle this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)); |
Copilot
AI
Sep 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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))); |
…
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