PSLogs
This project has adopted the following policies
Project status
About
PSLogs is a fork of the Logging module created by Massimo Bonvicini. Sadly the project is no longer maintained. In the readme in the original repo the author encourages people to reach out to become the owner of the repo so that it can continue to be developed. I've done this but have not gotten any response. therefore I have forked the project to continue development of the module.
There are a number of logging modules out there, most of them are quite simple and performs the task of logging to console and file very well. What is different with this module (that I really like) is that the logging target is split up into plugins. Of course there is console and file but a number of other targets like elastic search, email, slack, teams, winevent etc.
After the fork a couple of additional targets has been added like SQLite, Ntfy, OutputDebugString and GELF.
Another reason I really like this logging module is that it handles logging in a separate thread. Your script can keep doing its thing instead of waiting for each log message to be written.
Installation
PowerShell Gallery
To install from the PowerShell gallery using PowerShellGet run the following command:
Install-Module PSLogs -Scope CurrentUser
TL;DR
Set-LoggingDefaultLevel -Level 'WARNING'
Add-LoggingTarget -Name Console
Add-LoggingTarget -Name File -Configuration @{Path = 'C:\Temp\example_%{+%Y%m%d}.log'}
$Level = 'DEBUG', 'INFO', 'WARNING', 'ERROR'
foreach ($i in 1..100) {
Write-Log -Level ($Level | Get-Random) -Message 'Message n. {0}' -Arguments $i
Start-Sleep -Milliseconds (Get-Random -Min 100 -Max 1000)
}
Wait-Logging # See Note
NOTE
When used in unattended scripts (scheduled tasks, spawned process) you need to call Wait-Logging to avoid loosing messages. If you run your main script in an interactive shell that stays open at the end of the execution you could avoid using it (keep in mind that if there are messages in the queue when you close the shell, you'll lose them)
Docs
Please the full documentation on the docs site
Build and release
See BUILDING.md for local build and test commands, dependency version pins, and the manual Prepare release workflow.
License
This project is licensed under the MIT License
Included attributions from original repo
Special thanks to:
- Boe Prox (@proxb) for his work on runspaces