vscode-powershell icon indicating copy to clipboard operation
vscode-powershell copied to clipboard

Logpoints

Open General-Gouda opened this issue 8 years ago • 13 comments

I did not see an open or closed issue related to the newer VS Code Logpoint feature so I thought I'd add one.

Having the ability to have specific log output to console without needing to write the code directly through the Logpoint functionality would be useful for debug purposes.

General-Gouda avatar Jul 13 '18 19:07 General-Gouda

Looks like the feature for VSCode is here.

@General-Gouda would you be able to give a small motivating example?

rjmholt avatar Jul 13 '18 20:07 rjmholt

I have started work on this but got side-tracked. We already support a form Logpoints way before VSCode added the concept. Take a look at the Tracepoints section of this blog post - https://blogs.technet.microsoft.com/heyscriptingguy/2017/02/06/debugging-powershell-script-in-visual-studio-code-part-1/

BTW this issue should probably be logged in https://github.com/powershell/powershelleditorservices since all the work needs to be done there.

rkeithhill avatar Jul 13 '18 20:07 rkeithhill

@rjmholt I do a lot of work with Active Directory and with Exchange Online. Many of the cmdlets do not return any console output and so I need to inject some sort of output to know what user I'm iterating through. Or, I will simply output the index number.

Since VS Code doesn't (yet) support Write-Progress I could see where outputting the index number through logpoints would be helpful rather than killing kittens with a Write-Host or something. It would also keep the code cleaner. I don't always need output on a saved script. Sometimes I just want to know it worked the first time I wrote it and then save it for later.

@rkeithhill I'll give tracepoints a try the next time I write a script like this. One point of feedback is that tracepoints appear to need more complex expressions. Is it possible to simply output a variable's value by typing in "$var" as the expression or does it have to be contained in a logic statement such as IF?

General-Gouda avatar Jul 18 '18 15:07 General-Gouda

tracepoints appear to need more complex expressions

Agreed, Keep in mind the trace points implementation is just using Set-PSBreakpoint -Line xx -Action {}. That is, you can get the same functionality with raw PowerShell.

Implementing logpoints, will take an expression like this $var and integrate it into an Action like so: { <script to execute>; continue } e.g. {$var; continue}.

rkeithhill avatar Jul 18 '18 17:07 rkeithhill

This is supported now 🎉

TylerLeonhardt avatar Apr 22 '20 02:04 TylerLeonhardt

How does this work? I tried with the Examples folder DebugTest.ps1 file. I set up a Log Point message of i is $i on line 12 and the $i is not interpolated. Neither is i is {$i}. How do you specify a variable so that its value will be logged?

rkeithhill avatar Apr 22 '20 04:04 rkeithhill

It would appear that I used the wrong quotes 😅

https://github.com/PowerShell/PowerShellEditorServices/blob/master/src/PowerShellEditorServices/Services/DebugAdapter/Debugging/BreakpointApiUtils.cs#L180

Can you open an issue for supporting interpolation @rkeithhill?

Or perhaps a PR 🙏

TylerLeonhardt avatar Apr 22 '20 05:04 TylerLeonhardt

I'll do that tonight, if you can wait.

rkeithhill avatar Apr 22 '20 18:04 rkeithhill

Issue submitted #2654

rkeithhill avatar Apr 22 '20 18:04 rkeithhill

I'll see if I can get a PR in here on my lunch break.

rkeithhill avatar Apr 22 '20 18:04 rkeithhill

Bah, should have submitted that issue to PSES. Can you move it or should we leave it where it is?

rkeithhill avatar Apr 22 '20 19:04 rkeithhill

PR submitted - https://github.com/PowerShell/PowerShellEditorServices/pull/1270

rkeithhill avatar Apr 22 '20 19:04 rkeithhill

It's ok where it is :)

TylerLeonhardt avatar Apr 22 '20 20:04 TylerLeonhardt