Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 38bd1d4

Browse files
Joel BennettJoel Bennett
authored andcommitted
Update ReadMe documentation
1 parent 860c84b commit 38bd1d4

File tree

5 files changed

+79
-9
lines changed

5 files changed

+79
-9
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,3 +214,5 @@ pip-log.txt
214214

215215
#Mr Developer
216216
.mr.developer.cfg
217+
218+
Output/

Build.ps1

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[CmdletBinding()]
2+
param($OutputDirectory = $("$PSScriptRoot\Output"), [switch]$Force)
3+
4+
5+
Remove-Item $OutputDirectory -Recurse -Confirm:(!$Force)
6+
7+
8+
Copy-Item $PSScriptRoot\Module -Destination $OutputDirectory -recurse
9+
10+
dotnet build -c Release
11+
Get-ChildItem bin/Release -recurse -filter *.dll |
12+
Move-Item -Destination $OutputDirectory\PowerShellLogging\

README.md

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,51 @@
11
PowerShellLoggingModule
22
=======================
3-
Uses Reflection to intercept text output headed for the PowerShell
4-
console or ISE. Lines of output are sent to any number of
5-
subscriber objects for the purpose of producing complete log files
6-
of script output (including date/timestamps) without the need for
7-
extra code by the script author.
3+
Uses Reflection to intercept text output headed for the PowerShell console.
4+
All lines of output are sent to any number of subscriber objects
5+
producing complete log files of script output (adding date/timestamps)
6+
without needing extra code by the script author.
87

9-
The source code is maintained on GitHub. If you would like to use
10-
the module but can't compile it yourself, you can install it with
11-
PowerShellGet:
8+
The upside is that any text which would have shown up in the console is logged,
9+
and the downside is that only that text is logged.
10+
For example, verbose output is only logged if VerbosePreference is Continue...
11+
12+
13+
Supports PowerShell 2, 3, 4, 5, 6 and 7
14+
15+
16+
Install from the PowerShell Gallery
17+
==================================
1218

1319
```posh
1420
Install-Module PowerShellLogging
1521
```
1622

17-
Or download a zip file of the module from:
23+
Compile your own copy
24+
====================
25+
26+
You can run `build.ps1` to assembly a copy in an `Output` folder,
27+
or you can just compile the assembly with:
28+
29+
```posh
30+
dotnet build -c Release
31+
```
32+
33+
Testing
34+
=======
35+
36+
The test cases are very minimal (basically just covering the fact that it logs, and testing a couple of edge cases where it used to fail to log). Despite that, weand have some problems due to the way that WindowsPowerShell breaks when they fail.
37+
38+
As a result, _to be sure that the tests are actually working_ (reporting the correct results), you should run each test case in a new session. There is a wrapper script `test.ps1` which you can use to do that, it basically just runs each test case in `PowerShell` and `pwsh` to ensure everything is working in both WindowsPowerShell and PowerShell core. E.g.:
39+
40+
```
41+
foreach ($testcase in Get-ChildItem Tests\*.Tests.ps1) {
42+
powershell -NoProfile -Command Invoke-Pester $testcase.FullName
43+
}
44+
```
45+
46+
Alternative Download
47+
===================
48+
49+
Note, the original version is also available from:
1850

1951
http://gallery.technet.microsoft.com/scriptcenter/Enhanced-Script-Logging-27615f85

Test.ps1

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# The tests in here do not work properly in PowerShell 5.x
2+
# If you run them all at once, you will get a lot of FALSE PASSES using the old code
3+
# Running one test at a time in a new powershell session solves this problem:
4+
if (Get-Command powershell.exe -ErrorAction SilentlyContinue) {
5+
foreach ($testcase in ls $PSScriptRoot\Tests\*.Tests.ps1) {
6+
powershell -NoProfile -Command Invoke-Pester $testcase.FullName
7+
}
8+
} else {
9+
Write-Warning "Skipping Windows PowerShell tests"
10+
}
11+
12+
if (Get-Command pwsh -ErrorAction SilentlyContinue) {
13+
foreach ($testcase in ls $PSScriptRoot\Tests\*.Tests.ps1) {
14+
pwsh -NoProfile -Command Invoke-Pester $testcase.FullName
15+
}
16+
} else {
17+
Write-Warning "Skipping PowerShell Core tests"
18+
}
19+
}

Tests/Simple.Tests.ps1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Describe "It should work when called from scripts run by PowerShell.Invoke" {
1010
Write-Host 'This is a host test'
1111
'Returned OK'
1212
Write-Verbose 'This is a verbose test' -Verbose
13+
# Does not output, because Verbose is suppressed
14+
Write-Verbose 'This is a another verbose test'
1315
Disable-LogFile $Logging
1416
}
1517

@@ -54,5 +56,8 @@ Describe "It should work when called from scripts run by PowerShell.Invoke" {
5456
(Get-Content $Path) -match ".*This is a verbose test$" | Should -Not -BeNullOrEmpty
5557
}
5658

59+
It "Should not log verbose that's not output" -Skip:(!(Test-Path $Path)) {
60+
(Get-Content $Path) -match ".*This is another verbose test$" | Should -BeNullOrEmpty
61+
}
5762

5863
}

0 commit comments

Comments
 (0)