Skip to content
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

Write-*Log CmdLets do not support pipeline input #19

Open
mamidenn opened this issue Jun 26, 2021 · 2 comments
Open

Write-*Log CmdLets do not support pipeline input #19

mamidenn opened this issue Jun 26, 2021 · 2 comments

Comments

@mamidenn
Copy link

I would like to be able to pipe the output of CmdLets or called programs into Write-*Log. Currently, only the last element of the input gets actually logged.

New-Logger | Add-SinkConsole | Start-Logger
'Foo', 'Bar', 'Baz' | Write-InfoLog
Close-Logger

Expected:

[13:37:00 INF] Foo
[13:37:00 INF] Bar
[13:37:00 INF] Baz

# Or

[13:37:00 INF] Foo
Bar
Baz

Actual:

[13:37:00 INF] Baz

This is due to the CmdLets using ValueFromPipeline for the $MessageTemplate parameter but not wrapping the execution body in a Process block. Basically, all that needs to be done is replace this

Write-Log -MessageTemplate $MessageTemplate -Logger $Logger -Exception $Exception -ErrorRecord $ErrorRecord -PropertyValues $PropertyValues -PassThru:$PassThru

with this in all the CmdLets:

Process {
    Write-Log -MessageTemplate $MessageTemplate -Logger $Logger -Exception $Exception -ErrorRecord $ErrorRecord -PropertyValues $PropertyValues -PassThru:$PassThru
}

I can open a PR if you are interested in this.
Also big props for this nice project 👍.

mamidenn added a commit to mamidenn/PoShLog that referenced this issue Jun 27, 2021
mamidenn added a commit to mamidenn/PoShLog that referenced this issue Jun 27, 2021
@TomasBouda
Copy link
Member

hi again Martin, you rock 👍 thanks for fixing this
saw your PR, I'll fix the pipeline(yes, it fails because of unrelated issue) and then I'll merge it in.

I have some unfinished changes in PoShLog, so I will release your fix when I'm done.

@TomasBouda
Copy link
Member

Hi, I've relesed 2.2.0-preview1 to test some changes. You can verify your bugfixes there👍
Thanks again 🥇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants