Skip to content

0x4c6565/PSLogger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 

Repository files navigation

PSLogger

A logging module for PowerShell

Importing Module

Import-Module C:\Path\To\PSLogger.psm1

Log Targets:

One or more log targets must be added into the logger before any logging will be possible.

The module has several pre-defined log targets, each sharing the following common parameters:

  • Name: (Required) A unique name for the target
  • MinLevel: Minimum log level (Default: INFO)
  • MessageFormat: Format of log message (Default: {{date}} - {{level}} - [{{stack}}] --> {{message}})
  • Passive: Specifies that target should be passive - target must be explicitly targeted

File Target

This target will log to a single log file

Add-LoggerFileTarget [-Name] [-MinLevel] [-MessageFormat] [-Passive] [-LogPath]

  • LogPath: Path of log file (Default: $Env:TEMP\{Name}.log)

Host Target

This target will output to host

Add-LoggerHostTarget [-Name] [-MinLevel] [-MessageFormat] [-Passive]

Custom target

More log targets can be added via Add-LoggerTarget:

Add-LoggerTarget [-Name] [-MinLevel] [-MessageFormat] [-Passive] [-Invoke] [-Parameters]

  • Invoke: (Required) A scriptblock with a parameter Message, which will be invoked by the logger. Level and Parameters parameters will be passed also, if available
  • Parameters A hashtable of parameters which will be passed into Invoke

Basic Usage

Commands

Write-LoggerTrace [-Message] [-Target]

Write-LoggerDebug [-Message] [-Target]

Write-LoggerInfo [-Message] [-Target]

Write-LoggerWarn [-Message] [-Target]

Write-LoggerError [-Message] [-Target]

Write-LoggerFatal [-Message] [-Target] [-ExitCode]

Aliases

Aliases are also defined for writing logs:

Logger.Trace

Logger.Debug

Logger.Info

Logger.Warn

Logger.Error

Logger.Fatal

Examples

> Write-LoggerInfo "Testing log"
> "an error occurred","oops" | Write-LoggerError
> Write-LoggerWarn "Testing log file" -Target LogFile

About

A logging module for PowerShell

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published