forked from microsoft/winget-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Copilot/add logs cmtrace format #4
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
Draft
Tom Plant (pl4nty)
wants to merge
7
commits into
master
Choose a base branch
from
copilot/add-logs-cmtrace-format
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0c7fc58
Run GitHub Copilot cloud agent on Windows
pl4nty 50514bf
Initial plan
Copilot 4125656
Add LoggingUseCMTrace setting with CMTrace log format support and tests
Copilot ad9fd58
Rename CMTrace to CCM, change bool setting to logging.format enum, adβ¦
Copilot 046bef9
Fix spelling check: add 'fff' (datetime milliseconds token) to expectβ¦
Copilot f46a954
Address review: move format syntax to enum comment, remove redundant β¦
Copilot 261302e
Fix LogFileFormat
pl4nty File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -179,6 +179,7 @@ fdw | |
| fdwgp | ||
| FECAFEB | ||
| fedorapeople | ||
| fff | ||
| fileinuse | ||
| filemode | ||
| Filetime | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| name: Build MSIX | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| push: | ||
| branches: | ||
| - 'copilot/**' | ||
| paths: | ||
| - 'src/**' | ||
| - '.github/workflows/build-msix.yml' | ||
| pull_request: | ||
| paths: | ||
| - 'src/**' | ||
| - '.github/workflows/build-msix.yml' | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: windows-latest | ||
| timeout-minutes: 120 | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| strategy: | ||
| matrix: | ||
| platform: [x64] | ||
| configuration: [Release] | ||
|
|
||
| env: | ||
| solution: 'src\AppInstallerCLI.sln' | ||
| buildOutDir: ${{ github.workspace }}\src\${{ matrix.platform }}\${{ matrix.configuration }} | ||
| appxPackageDir: ${{ github.workspace }}\artifacts\${{ matrix.platform }}\AppxPackages | ||
|
|
||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Install NuGet | ||
| uses: NuGet/setup-nuget@v2 | ||
|
|
||
| - name: Restore Solution (NuGet) | ||
| run: nuget restore ${{ env.solution }} | ||
|
|
||
| - name: Restore AppInstallerCLIPackage (NuGet) | ||
| run: nuget restore src\AppInstallerCLIPackage\AppInstallerCLIPackage.wapproj | ||
|
|
||
| - name: Restore .NET projects | ||
| run: dotnet restore src | ||
|
|
||
| - name: Integrate vcpkg | ||
| run: | | ||
| & "$env:VCPKG_INSTALLATION_ROOT\vcpkg.exe" integrate install | ||
| shell: pwsh | ||
|
|
||
| - name: Add MSBuild to PATH | ||
| uses: microsoft/setup-msbuild@v2 | ||
|
|
||
| - name: Build Solution | ||
| run: | | ||
| msbuild ${{ env.solution }} ` | ||
| /p:Platform=${{ matrix.platform }} ` | ||
| /p:Configuration=${{ matrix.configuration }} ` | ||
| /p:AppxBundlePlatforms="${{ matrix.platform }}" ` | ||
| /p:AppxPackageDir="${{ env.appxPackageDir }}" ` | ||
| /p:AppxBundle=Always ` | ||
| /p:UapAppxPackageBuildMode=SideloadOnly ` | ||
| /m | ||
| shell: pwsh | ||
|
|
||
| - name: Upload MSIX artifacts | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: msix-${{ matrix.platform }}-${{ matrix.configuration }} | ||
| path: ${{ env.appxPackageDir }} | ||
| retention-days: 7 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| name: "Copilot Setup Steps" | ||
|
|
||
| # Automatically run the setup steps when they are changed to allow for easy validation, and | ||
| # allow manual testing through the repository's "Actions" tab | ||
| on: | ||
| workflow_dispatch: | ||
| push: | ||
| paths: | ||
| - .github/workflows/copilot-setup-steps.yml | ||
| pull_request: | ||
| paths: | ||
| - .github/workflows/copilot-setup-steps.yml | ||
|
|
||
| jobs: | ||
| # The job MUST be called `copilot-setup-steps` or it will not be picked up by Copilot. | ||
| copilot-setup-steps: | ||
| runs-on: windows-latest | ||
|
|
||
| # Set the permissions to the lowest permissions possible needed for your steps. | ||
| # Copilot will be given its own token for its operations. | ||
| permissions: | ||
| # If you want to clone the repository as part of your setup steps, for example to install dependencies, you'll need the `contents: read` permission. | ||
| # If you don't clone the repository in your setup steps, Copilot will do this for you automatically after the steps complete. | ||
| contents: read |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -29,6 +29,53 @@ namespace AppInstaller::Logging | |||
| return std::move(strstr).str(); | ||||
| } | ||||
|
|
||||
| // Formats a log line in CCM (CMTrace-compatible) format. | ||||
| // CCM log format: <![LOG[message]LOG]!><time="HH:mm:ss.fff+###" date="MM-dd-YYYY" component="channel" context="" type="N" thread="TID" file=""> | ||||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
| std::string ToCCMLogLine(Channel channel, Level level, std::string_view message) | ||||
| { | ||||
| auto now = std::chrono::system_clock::now(); | ||||
| auto tt = std::chrono::system_clock::to_time_t(now); | ||||
| tm localTime{}; | ||||
| _localtime64_s(&localTime, &tt); | ||||
|
|
||||
| auto sinceEpoch = now.time_since_epoch(); | ||||
| auto leftoverMillis = std::chrono::duration_cast<std::chrono::milliseconds>(sinceEpoch) - std::chrono::duration_cast<std::chrono::seconds>(sinceEpoch); | ||||
|
|
||||
| // Get UTC bias in minutes (positive means west of UTC, CMTrace uses positive for west) | ||||
| long timezoneBiasSeconds = 0; | ||||
| _get_timezone(&timezoneBiasSeconds); | ||||
| long biasMins = timezoneBiasSeconds / 60; | ||||
|
|
||||
| // CCM type: 1=Info/Verbose, 2=Warning, 3=Error/Critical | ||||
| int type; | ||||
| switch (level) | ||||
| { | ||||
| case Level::Warning: type = 2; break; | ||||
| case Level::Error: | ||||
| case Level::Crit: type = 3; break; | ||||
| default: type = 1; break; | ||||
| } | ||||
|
|
||||
| std::stringstream strstr; | ||||
| strstr << "<![LOG[" << message << "]LOG]!>" | ||||
| << "<time=\"" | ||||
| << std::setw(2) << std::setfill('0') << localTime.tm_hour << ":" | ||||
| << std::setw(2) << std::setfill('0') << localTime.tm_min << ":" | ||||
| << std::setw(2) << std::setfill('0') << localTime.tm_sec << "." | ||||
| << std::setw(3) << std::setfill('0') << leftoverMillis.count() | ||||
| << "+" << biasMins << "\"" | ||||
| << " date=\"" | ||||
| << std::setw(2) << std::setfill('0') << (1 + localTime.tm_mon) << "-" | ||||
| << std::setw(2) << std::setfill('0') << localTime.tm_mday << "-" | ||||
| << (1900 + localTime.tm_year) << "\"" | ||||
| << " component=\"" << GetChannelName(channel) << "\"" | ||||
| << " context=\"\"" | ||||
| << " type=\"" << type << "\"" | ||||
| << " thread=\"" << GetCurrentThreadId() << "\"" | ||||
| << " file=\"\">"; | ||||
| return std::move(strstr).str(); | ||||
| } | ||||
|
|
||||
| // Determines the difference between the given position and the maximum as an offset. | ||||
| std::ofstream::off_type CalculateDiff(const std::ofstream::pos_type& position, std::ofstream::off_type maximum) | ||||
| { | ||||
|
|
@@ -94,7 +141,15 @@ namespace AppInstaller::Logging | |||
|
|
||||
| void FileLogger::Write(Channel channel, Level level, std::string_view message) noexcept try | ||||
| { | ||||
| std::string log = ToLogLine(channel, level, message); | ||||
| std::string log; | ||||
| if (Settings::User().Get<Settings::Setting::LoggingFormat>() == LogFileFormat::CCM) | ||||
| { | ||||
| log = ToCCMLogLine(channel, level, message); | ||||
| } | ||||
| else | ||||
| { | ||||
| log = ToLogLine(channel, level, message); | ||||
| } | ||||
| WriteDirect(channel, level, log); | ||||
| } | ||||
| catch (...) {} | ||||
|
|
||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -98,6 +98,15 @@ namespace AppInstaller::Logging | |
| ShortGuid, | ||
| }; | ||
|
|
||
| // The format used when writing log entries to a file. | ||
| enum class LogFileFormat | ||
| { | ||
| // Default WinGet format: "<timestamp> <level> [channel] message" | ||
| WinGet, | ||
| // CCM/CMTrace-compatible format recognized by CMTrace and Microsoft Endpoint Configuration Manager log viewers | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CCM/CMTrace-compatible format: "format syntax here" |
||
| CCM, | ||
| }; | ||
|
|
||
| // Indicates a location of significance in the logging stream. | ||
| enum class Tag | ||
| { | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.