-
Notifications
You must be signed in to change notification settings - Fork 155
Extended debug logging #1729
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
Merged
spetersenms
merged 54 commits into
microsoft:main
from
spetersenms:ExtendedDebugLogging
Jul 16, 2025
Merged
Extended debug logging #1729
Changes from all commits
Commits
Show all changes
54 commits
Select commit
Hold shift + click to select a range
c3309d5
Importing debug helper.
spetersenms 68b9759
First draft of debug helper
spetersenms 3fd68e6
Testing new debug helper functions.
spetersenms 934bf8f
Changing type for param
spetersenms 4520382
Log info on debug log variable.
spetersenms 90e03b1
Add debug context var to env variable.
spetersenms fd9969d
Removed runner context from top level env statement as it's not avail…
spetersenms fe23a7a
Testing injecting runner context in action environment var section.
spetersenms db7531a
Added [Debug] tag to debug logs.
spetersenms c3d4a4d
Merge branch 'main' into ExtendedDebugLogging
spetersenms 9f05255
Testing RUNNER_DEBUG variable.
spetersenms 70fdfb2
Switching to use RUNNER_DEBUG env var instead of passing github context.
spetersenms 44ae296
Improved formatting of debug messages.
spetersenms c268aa8
Coloring debug output
spetersenms 9e83be6
Using escape char that works in both Pwsh 5 and 7
spetersenms d3b265f
Importing debug log helper in tests.
spetersenms 72ec7b2
Importing logging module globally to make it useable by tests.
spetersenms da61332
pre-commit
spetersenms 28d548b
Merge branch 'main' into ExtendedDebugLogging
spetersenms 47b7f68
Merge branch 'main' into ExtendedDebugLogging
spetersenms e1c006b
Merge branch 'main' into ExtendedDebugLogging
spetersenms 6dae42f
Merge branch 'main' into ExtendedDebugLogging
spetersenms 0875483
Fixed inconsistent log.
spetersenms 6ea22d4
Made parameters param of function debug optional, added helper functi…
spetersenms 17224be
Merge branch 'main' into ExtendedDebugLogging
spetersenms 868b910
pre-commit
spetersenms 8d571fc
Merge branch 'ExtendedDebugLogging' of github.com:spetersenms/AL-Go i…
spetersenms b00a679
Merge branch 'main' into ExtendedDebugLogging
spetersenms 2168fb1
Merge branch 'main' into ExtendedDebugLogging
spetersenms 5f11ac6
Moving debug module to module folder, and including OutPut* functions…
spetersenms 6c8aaa5
Testing stuff.
spetersenms fb8d73d
Added detailed documentation to module.
spetersenms 96fa8ed
Removed debug log.
spetersenms ad0e519
Loading debug module in AL-Go helper.
spetersenms eef9886
Fixing path to debug module in test helper.
spetersenms 7b0389c
pre-commit
spetersenms 6030d7a
Comment explaining Char27
spetersenms 5f60c7f
Loading debug module in local dev env.
spetersenms f851b03
pre-commit
spetersenms e549385
Using GitHub ::debug:: functionality.
spetersenms 89778f4
Using updated debug function names.
spetersenms d7e1ec3
Corrected exported names.
spetersenms 1f90d93
Corrected regex and added AL-Go prefix to debug messages.
spetersenms 9108ca2
Documentation correction
spetersenms 7bee984
Pre-commit + changing variable name.
spetersenms 0dc0d57
Using .InvocationInfo.BoundParamters to fetch function parameters.
spetersenms b7557c7
Using Write-Debug instead of Write-Host for running locally.
spetersenms 7d5ee43
Adding debug module to cloudDevEnv.
spetersenms 13eebc5
Merge branch 'main' into ExtendedDebugLogging
spetersenms 96baa72
Merge branch 'main' into ExtendedDebugLogging
spetersenms 0048d74
Using Write-Warning when running locally and removed manual check on …
spetersenms 999b33f
Merge branch 'ExtendedDebugLogging' of github.com:spetersenms/AL-Go i…
spetersenms b6c3876
Improved function documentation.
spetersenms c639a36
Added release notes.
spetersenms 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
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 |
---|---|---|
@@ -0,0 +1,218 @@ | ||
|
||
if ($env:GITHUB_ACTIONS -eq "true") { | ||
$runningLocal = $false | ||
} else { | ||
$runningLocal = $true | ||
} | ||
|
||
# Colors | ||
$colorCodeRed = '31' | ||
$colorCodeGreen = '32' | ||
$colorCodeYellow = '33' | ||
$colorCodeBlue = '34' | ||
$colorCodeMagenta = '35' | ||
$colorCodeCyan = '36' | ||
|
||
<# | ||
.SYNOPSIS | ||
Writes debug information about the function call and its parameters if extended debug logging is enabled or running locally. | ||
.DESCRIPTION | ||
Writes debug information about the function call and its parameters to the console if extended debug logging is enabled or running locally. | ||
Automatically retrieves the caller's name and arguments from the call stack. | ||
#> | ||
function OutputDebugFunctionCall { | ||
try { | ||
$caller = (Get-PSCallStack)[1] | ||
$callerName = $caller.Command | ||
$callerParameters = $caller.InvocationInfo.BoundParameters | ||
|
||
OutputDebug "Function '$callerName' called with parameters:" | ||
if ($callerParameters.Count -eq 0) { | ||
OutputDebug "None" | ||
} | ||
foreach ($key in $callerParameters.Keys) { | ||
$val = $callerParameters[$key] | ||
OutputDebug "-$($key): $val" | ||
} | ||
} catch { | ||
OutputDebug "Unable to retrieve function information from call stack." | ||
} | ||
} | ||
|
||
<# | ||
.SYNOPSIS | ||
Starts a console log group. | ||
.DESCRIPTION | ||
Starts a console log group. All subsequent log messages will be grouped under this message until OutputGroupEnd is called. | ||
If running locally, it writes a simple message to the console. If running in GitHub Actions, it uses the `::group::` command to create a collapsible group in the log. | ||
.PARAMETER Message | ||
Name/Title of the group. | ||
#> | ||
function OutputGroupStart { | ||
param ( | ||
[Parameter(Mandatory = $true)] | ||
[string] $Message | ||
) | ||
|
||
if ($runningLocal) { | ||
Write-Host "==== Group start: $Message ====" | ||
} else { | ||
Write-Host "::group::$Message" | ||
} | ||
} | ||
|
||
<# | ||
.SYNOPSIS | ||
Ends a console log group. | ||
.DESCRIPTION | ||
Ends a console log group started with OutputGroupStart. All subsequent log messages will be outside of this group. | ||
#> | ||
function OutputGroupEnd { | ||
if ($runningLocal) { | ||
Write-Host "==== Group end ====" | ||
} else { | ||
Write-Host "::endgroup::" | ||
} | ||
} | ||
|
||
<# | ||
.SYNOPSIS | ||
Writes to console with optional color. | ||
.DESCRIPTION | ||
Writes a message to the console with an optional color. If no color is specified, the message is written in the default console color. | ||
.PARAMETER Message | ||
Message to be written to console. | ||
.PARAMETER Color | ||
Optional color for the message. Valid values are 'Red', 'Green', 'Yellow', 'Blue', 'Magenta', 'Cyan'. | ||
#> | ||
function OutputColor { | ||
param ( | ||
[Parameter(Mandatory = $true)] | ||
[string] $Message, | ||
[Parameter(Mandatory = $false)] | ||
[ValidateSet('Red', 'Green', 'Yellow', 'Blue', 'Magenta', 'Cyan')] | ||
[string] $Color | ||
) | ||
|
||
if ($Color) { | ||
$colorCode = 0 | ||
switch ($Color) { | ||
'Red' { $colorCode = $colorCodeRed } | ||
'Green' { $colorCode = $colorCodeGreen } | ||
'Yellow' { $colorCode = $colorCodeYellow } | ||
'Blue' { $colorCode = $colorCodeBlue } | ||
'Magenta' { $colorCode = $colorCodeMagenta } | ||
'Cyan' { $colorCode = $colorCodeCyan } | ||
} | ||
# char 27 is the escape character for ANSI codes which works in both PS 5 and 7. | ||
Write-Host "$([char] 27)[${colorCode}m$Message$([char] 27)[0m" | ||
} else { | ||
Write-Host $Message | ||
} | ||
} | ||
|
||
<# | ||
.SYNOPSIS | ||
Write an error message to the console. | ||
.DESCRIPTION | ||
Writes an error message to the console. Throws an exception if running locally, otherwise formats the message for GitHub Actions. | ||
.PARAMETER Message | ||
Message to be written to console. | ||
#> | ||
function OutputError { | ||
|
||
Param( | ||
[string] $message | ||
) | ||
|
||
if ($runningLocal) { | ||
throw $message | ||
} | ||
else { | ||
Write-Host "::Error::$($message.Replace("`r",'').Replace("`n",' '))" | ||
$host.SetShouldExit(1) | ||
} | ||
} | ||
|
||
<# | ||
.SYNOPSIS | ||
Write a warning message to the console. | ||
.DESCRIPTION | ||
Writes a warning message to the console. Uses Write-Warning if running locally, otherwise formats the message for GitHub Actions. | ||
.PARAMETER Message | ||
Message to be written to console. | ||
#> | ||
function OutputWarning { | ||
|
||
Param( | ||
[string] $message | ||
) | ||
|
||
if ($runningLocal) { | ||
Write-Warning $message | ||
} | ||
else { | ||
Write-Host "::Warning::$message" | ||
} | ||
} | ||
|
||
<# | ||
.SYNOPSIS | ||
Write a notice message to the console. | ||
.DESCRIPTION | ||
Writes a notice message to the console. Uses regular Write-Host if running locally, otherwise formats the message for GitHub Actions. | ||
.PARAMETER Message | ||
Message to be written to console. | ||
#> | ||
function OutputNotice { | ||
|
||
Param( | ||
[string] $message | ||
) | ||
|
||
if ($runningLocal) { | ||
Write-Host $message | ||
} | ||
else { | ||
Write-Host "::Notice::$message" | ||
} | ||
} | ||
|
||
<# | ||
.SYNOPSIS | ||
Mask a value in the log. | ||
.DESCRIPTION | ||
Masks a value in the log to prevent sensitive information from being displayed. If running locally, it writes the masked value to the console. | ||
.PARAMETER Value | ||
The value to be masked in the log. | ||
#> | ||
function MaskValueInLog { | ||
|
||
Param( | ||
[string] $value | ||
) | ||
|
||
if (!$runningLocal) { | ||
Write-Host "`r::add-mask::$value" | ||
} | ||
} | ||
|
||
<# | ||
.SYNOPSIS | ||
Write a debug message to the console. | ||
.DESCRIPTION | ||
Writes a debug message to the console. Uses Write-Debug if running locally, otherwise formats the message for GitHub Actions. | ||
.PARAMETER Message | ||
Message to be written to console. | ||
#> | ||
function OutputDebug { | ||
|
||
Param( | ||
[string] $message | ||
) | ||
|
||
if ($runningLocal) { | ||
Write-Debug $message | ||
spetersenms marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
else { | ||
Write-Host "::Debug::[AL-Go]$message" | ||
spetersenms marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
Export-ModuleMember -Function OutputColor, OutputDebugFunctionCall, OutputGroupStart, OutputGroupEnd, OutputError, OutputWarning, OutputNotice, MaskValueInLog, OutputDebug | ||
Export-ModuleMember -Variable debugLoggingEnabled |
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.