Powershell Logging Module
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.vscode
Images
PowerLumber
Test_Results
docs
spec
tests
.gitignore
LICENSE
PITCHME.md
PowerLumber.BuildSettings.ps1
appveyor.yml
build.ps1
deploy.PSDeploy.ps1
mkdocs.yml
module.build.ps1
readme.md

readme.md

PowerLumber

Simple Powershell Logging Module

Build status PS Gallery Coverage Status Documentation Status

Docs

Help

Getting Started

Install from the PSGallery and Import the module

Install-Module PowerLumber
Import-Module PowerLumber

More Information

For more information

This project was generated using Kevin Marquette's Full Module Plaster Template.

PowerLumber Info

Alt text

Overview

This powershell module includes commands to assist with logging.

Requirements

Powershell version 5.0 (It may work with older versions, but its not tested.)

Installation

Download the file and run the following line

Import-Module <path>\PowerLumber.psm1

Copy and paste these lines. c:\temp needs to exist

  $webclient = New-Object System.Net.WebClient  
  $filepath = "C:\temp\PowerLumber.psm1"  
  $url = "https://raw.github.com/jpsider/PowerLumber/master/PowerLumber.psm1"  
  $webclient.DownloadFile($url,$filepath)  
  Import-module $filepath  

Available Functions

Clear-LogDirectory New-Log
Write-Log
Invoke-RollLog
Write-LogLevel

Examples

Create New Log file

New-Log -logfile c:\temp\new.log

Clear log files in path older than specified days

Clear-LogDirectory -Path "c:\temp" -DaysBack 3

Log a message to logfile with no console output

Write-Log -Message "I love lamp" -Logfile "C:\temp\mylog.log" -OutputStyle noConsole

Log a message to logfile with console output

Write-Log -Message "I love lamp" -Logfile "C:\temp\mylog.log" -OutputStyle both  

Log a message with only console output (not sure why'd you would specify a log file, but you can!)

Write-Log -Message "I love lamp" -Logfile "C:\temp\mylog.log" -OutputStyle consoleOnly

Log a message to logfile with console output shorter

Write-Log -Message "I love lamp" -Logfile "C:\temp\mylog.log"

Log a message with only console output

Write-Log -Message "I love lamp" -OutputStyle consoleOnly  

Understanding Write-LogLevel

-RunLogLevel is meant to be a system/script wide Level  
-MsgLevel is meant to be for a specific Log Message  

This Module will only write Equal or Lower LogLevels based on the Message Level compared to the -RunLogLevel

Setting -RunLogLevel to All, will force all Messages to be written and displayed

Write-LogLevel -Message "I love lamp" -Logfile "C:\temp\mylog.log" -RunLogLevel All -MsgLevel TRACE

Setting -RunLogLevel to CONSOLEONLY will not write any messages, all log messages will be displayed to the console

Write-LogLevel -Message "I love lamp" -Logfile "C:\temp\mylog.log" -RunLogLevel CONSOLEONLY -MsgLevel CONSOLEONLY

The next two examples will log different items

Logs a Warning message to a log file and console
Write-LogLevel -Message "I love lamp" -Logfile "C:\temp\mylog.log" -RunLogLevel WARN -MsgLevel WARN
Logs a DEBUG Message to the console Only. No message written to a log file
Write-LogLevel -Message "I love lamp" -Logfile "C:\temp\mylog.log" -RunLogLevel FATAL -MsgLevel DEBUG