Git Product home page Git Product logo

simple-ps-logger's Introduction

Simple PowerShell Logging Module logo

Build Status Tests Code Quality last commit license


Introduction

SimplePSLogger provides an easy yet powerful way to save or display your logs.

Features

  • 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 โšก๏ธ

Modules

Below is a table contains our modules including built in provider modules.

Description Module Name PowerShell Gallery Link Downloads
SimplePSLogger SimplePSLogger SimplePSLogger Downloads
SimplePSLogger.Console SimplePSLogger.Console Sub module
SimplePSLogger.File SimplePSLogger.File Sub module
SimplePSLogger.AzLogAnalytics SimplePSLogger.AzLogAnalytics Sub module

Installation

PowerShell Gallery

# Install pre-release version 
Install-Module -Name SimplePSLogger -Confirm

Import from Directory

Import-Module -Name drive:path\SimplePSLogger -Verbose

Read more about importing module here Import Module


Usage

Example 1

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"
Example 2

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"

Built in Providers

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

Supported Log Levels

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

Reporting Issues and Feedback

Issues

If you find any bugs when using this module, Please an issue on github

Feedback

If there is a feature you would like to see in SimplePSLogger file an issue on github

Show your love

Give a โญ if you find this project helpful!

simple-ps-logger's People

Contributors

dependabot[bot] avatar geekwhocodes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

simple-ps-logger's Issues

More PowerShelly Syntax

Summary of the new feature
Currently, we have to use method call(c# like syntax).

Proposed technical implementation details (optional)
It would be good if we have more PowerShelly syntax like Write-Log instead of $MyLogger.Log()

Azure DevOps Logging Provider

Summary of the new feature
Azure DevOps has custom syntax to format log messages, so writing Write-Information prints message in white color. It would be good if we have a provider that supports formatting log messages without adding Azure DeOpsy syntax.

Example - Write-Warning should use ##[warning] this prefix to print log message in yellow color.

Proposed technical implementation details (optional)
Good documentation is available here -
https://docs.microsoft.com/en-us/azure/devops/pipelines/scripts/logging-commands?view=azure-devops&tabs=powershell#formatting-commands

Write Tests using Pester

Currently there are no tests written for this project, I am not familiar with pester.
It would be great help if someone help with writing tests.

Rolling File Logging Provider

Summary of the new feature
Log files often grow bigger overtime and at certain point it becomes a problem. To overcome this problem, we can have roll over file which will automatically gets created on predefined/configured condition.
For example - Rolling file based on date-time or a day, file size etc.

Proposed technical implementation details (optional)
User can define rolling trigger policy, let's say when file size reaches 100MB, roll over to new file(which will get created automatically).
Same goes for date/day based rolling trigger policy, roll over every day(create new log file for every day).

Ability to register external logging providers

Summary of the new feature
Currently, there is not option to register external logging providers. You need to add logging providers as a nested modules in SimplePSLogger, that is not very flexible.

Proposed technical implementation details (optional)
User can write their own logging provider modules following current provider's structure and SimpleLogger can expose a method to register it.

Describe alternatives you've considered

  • NA

Additional context

  • NA

Create Rolling File Logging Provider

Summary of the new feature
Log files often grow bigger overtime and at certain point it becomes a problem. To overcome this problem, we can have roll over file which will automatically gets created on predefined/configured condition.
For example - Rolling file based on date-time or a day, file size etc.

Proposed technical implementation details (optional)
User can define rolling trigger policy, let's say when file size reaches 100MB, roll over to new file(which will get created automatically).
Same goes for date/day based rolling trigger policy, roll over every day(create new log file for every day).

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.