SimplePSLogger provides an easy yet powerful way to save or display your logs.
- Docs - SimplePSLogger Documentation
- Task Board - Board
- V2 Docs
- Built with π and PowerShell Core
- Easy to use
- Cross platform
- Simple Configuration π
- Pluggable
- Bring your own logging provider
- Open source your logging provider to share with your fellow PowerShellers, because sharing is caring
- Built in Providers π₯
- Start logging within a minute
- Lightning fast β‘οΈ
Below is a table contains our modules including built in provider modules.
Description | Module Name | PowerShell Gallery Link | Downloads |
---|---|---|---|
SimplePSLogger | SimplePSLogger |
||
SimplePSLogger.Console | SimplePSLogger.Console |
Sub module | |
SimplePSLogger.File | SimplePSLogger.File |
Sub module | |
SimplePSLogger.AzLogAnalytics | SimplePSLogger.AzLogAnalytics |
Sub module |
# Install pre-release version
Install-Module -Name SimplePSLogger -Confirm
Import-Module -Name drive:path\SimplePSLogger -Verbose
Read more about importing module here Import Module
Create new logger instance using New-SimplePSLogger
cmdlet:
<#
.PARAMETER Name
This can be used to identify for which purpose you are using this logger instance.
example - if you are performing task1
Simple logger will generate log message like this :
2020/06/12 15:48:31:2518 PM task1 information Log from task1
task1 is unique name you used while creating the instance. This will helpful to analyze your logs later.
#>
New-SimplePSLogger -Name "MyLogger"
# information log
Write-SimpleLog "Log message" "information"
# default log level
Write-SimpleLog "message" # In this case, SimplePSLogger will automatically use default(information) loglevel
$Object = @{User = @{Name= "geekwhocodes", LastLogin = "2020/06/12 15:48:31:2518 PM" } }
# Log PowerShell object, SimplePSLogger will automatically serialize this object
Write-SimpleLog $Object "warning"
# Note - DON'T forget to flush and remove logger instance/instances
# Flush bufferred logs
Clear-Buffer -Name "MyLogger"
# Remove all logger instances
Remove-SimplePSLogger -Name "MyLogger"
Create new logger instance using New-SimplePSLogger
cmdlet:
Read more about configuration
<#
.PARAMETER Name
This can be used to identify for which purpose you are using this logger instance.
example - if you are performing task1
Simple logger will generate log message like this :
2020/06/12 15:48:31:2518 PM task1 information Log from task1
task1 is unique name you used while creating the instance. This will helpful to analyze your logs later.
.PARAMETER Configuration
Configuration to use for logger instance.
#>
$SimplePSLoggerConfig = @{
Name = "az-analytics-example-buffered"
Providers = @{
File = @{
LiteralFilePath = "G:\Git\simple-ps-logger\ExamplesV2\example-with-config.log"
LogLevel = "information"
Enabled = $true
}
AzLogAnalytics = @{
Enabled = $true
LogLevel = "verbose"
#WorkspaceId = "****************" # Fetch from your secure store. example - KeyVault
#WorkspaceKey = "****************" # Fetch from your secure store. example - KeyVault
LogType = "GWCPSLogger" # https://docs.microsoft.com/en-us/azure/azure-monitor/platform/data-collector-api#record-type-and-properties
BufferSize = 50
Flush = $true
}
}
}
New-SimplePSLogger -Name "MyLogger" -Configuration $SimplePSLoggerConfig
# information log
Write-SimpleLog "Log message" "information"
# default log level
Write-SimpleLog "message" # In this case, SimplePSLogger will automatically use default(information) loglevel
$Object = @{User = @{Name= "geekwhocodes", LastLogin = "2020/06/12 15:48:31:2518 PM" } }
# Log PowerShell object, SimplePSLogger will automatically serialize this object
Write-SimpleLog $Object "warning"
# Note - DON'T forget to flush and remove logger instance/instances
# Flush bufferred logs
Clear-Buffer -Name "MyLogger"
# Remove all logger instances
Remove-SimplePSLogger -Name "MyLogger"
Provider | Description | Docs |
---|---|---|
Console | Outputs logs to console | Console Provider |
File | Writes logs to static file | File Provider |
AzLogAnalytics | Send logs to Azure Log Analytics Workspace | AzLogAnalytics Provider |
Rolling File | Writes logs to file | To do |
Level | Description |
---|---|
verbose | for verbose messages |
debug | for debug messages |
information | for information messages |
warning | for warning messages |
error | for error messages |
critical | for critical messages |
If you find any bugs when using this module, Please an issue on github
If there is a feature you would like to see in SimplePSLogger file an issue on github
Give a β if you find this project helpful!