Giter Site home page Giter Site logo

scriptlogger's Introduction

PowerShell Gallery - ScriptLogger GitHub - Release AppVeyor - master

ScriptLogger PowerShell Module

PowerShell Module to provide logging capabilities for PowerShell controller scripts.

Introduction

With the ScriptLogger module, you are able to log error, warning, informational and verbose messages into log files, the Windows event log and the current console host. You can start and stop the logger as required. Works great in cooperation with the ScriptConfig module to improve controller scripts.

Features

  • Start-ScriptLogger
    Start the script logger in the active PowerShell session.

  • Stop-ScriptLogger
    Stop the script logger in the active PowerShell session.

  • Set-ScriptLogger
    Update the script logger log configuration.

  • Get-ScriptLogger
    Get the active script logger object.

  • Write-VerboseLog
    Log a verbose message.

  • Write-InformationLog
    Log an information message.

  • Write-WarningLog
    Log a warning message.

  • Write-ErrorLog
    Log an error message.

Example

The following example show two options how to start the script logger, the logger management and how to log the log messages.

# Initialize the logger with default values
Start-ScriptLogger

# Second options, specify multiple custom settings for the logger
Start-ScriptLogger -Path 'C:\Temp\test.log' -Format '{0:yyyy-MM-dd}   {0:HH:mm:ss}   {1}   {2}   {3,-11}   {4}' -Level Warning -Encoding 'UTF8' -NoEventLog -NoConsoleOutput

# Start a second script logger with a dedicated name. The default script logger
# is always named 'Default'
Start-ScriptLogger -Name 'Logger2' -Path 'C:\Temp\test2.log'

# Get the current script logger configuration object
Get-ScriptLogger

# Update the script logger configuration
Set-ScriptLogger -Level Verbose

# Log an error record
try { 0 / 0 } catch { Write-ErrorLog -ErrorRecord $_ }

# Log an error message
Write-ErrorLog -Message 'My Error Message'

# Log a warning massage
Write-WarningLog -Message 'My Warning Message'

# Log an information message
Write-InformationLog -Message 'My Information Message'

# Log a verbose message
Write-VerboseLog -Message 'My Verbose Message'

# Write a log message into the log 2
Write-InformationLog -Name 'Logger2' -Message 'My Information Message in Log 2'

# Disable the logger
Stop-ScriptLogger

Versions

Please find all versions in the GitHub Releases section and the release notes in the CHANGELOG.md file.

Installation

Use the following command to install the module from the PowerShell Gallery, if the PackageManagement and PowerShellGet modules are available:

# Download and install the module
Install-Module -Name 'ScriptLogger'

Alternatively, download the latest release from GitHub and install the module manually on your local system:

  1. Download the latest release from GitHub as a ZIP file: GitHub Releases
  2. Extract the module and install it: Installing a PowerShell Module

Requirements

The following minimum requirements are necessary to use this module, or in other words are used to test this module:

  • Windows PowerShell 3.0
  • Windows Server 2008 R2 / Windows 7

Contribute

Please feel free to contribute by opening new issues or providing pull requests. For the best development experience, open this project as a folder in Visual Studio Code and ensure that the PowerShell extension is installed.

scriptlogger's People

Contributors

claudiospizzi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

scriptlogger's Issues

Add -Function parameter to Write-Log function

Hi, would it be able to add -Function parameter to Write-Log function and therefore to all logging functions as well?

So if you set up the $Global:ScriptLogger to

Start-ScriptLogger -Path 'C:\Temp\test.log' ...

and than use for example

Write-InformationLog -Message "Foo" -Function "Test"

the output will go to the 'C:\Temp\Test.log'.

Some idea for parameter for the Write-Log function

Param(
[Parameter(Mandatory = $false)]
[string] $Function= $Global:ScriptLogger.Path
)

Information message is not showed in console

With powershell 5 information message is not showed in console.
change line 97 of Write-Log.ps1 (add -InformationAction Continue)

'Information' { try { Write-Information -MessageData $Message -InformationAction Continue } catch { Write-Host $Message } }

Also to avoid exception message with write-errorlog change line 99
'Error' { $Host.UI.WriteErrorLine("ERROR: $ErrorRecord")}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.