Git Product home page Git Product logo

psglogthis's Introduction

Introduction

Send formatted messages to GrayLog by leveraging the PSOoGelf module.

The functions herein are a sister-module to PSGELF. They are better suited for application-level logging (as opposed to WinEvent logging found in PSGELF). The module automatically populates fields of log messages like the current machine's IP address, UTC DateTime, and Facility. Additionally, the functions provide a standard way to log PS Exception Objects. It also manages your connection to your GELF server throughout your scripts: you login once and send messages infinitely after that.

This module wraps PSOoGelf to automatically manage the objects created there. See that module for more details on GELF restrictions.

Example - Use the GELFMessage and GELFSender factories/orchestrators

Import-Module PSGLogThis

# initialize a connection to your GELF (Graylog?) server, used for the rest of the script
# alternatively, you can use unencrypted TCP or (unencrypted) UDP.
Initialize-GLT_Module `
    -TCP -Encrypt `
    -GelfServer "my.server.com" `
    -GelfPort 12345 `
    -Facility "MyDefaultApplicaitonFacility"


# wrappers for each level of log messages are provided:
# send a simple text log
Send-GLT_InfoLog "This is informational only"
Send-GLT_WarningLog "Woa there, something's up!"

# send a message with an attached object containing different fields (you can opt
# to override the default facility this way, or add other fields)
# I recommend using HashTables or PSCustomObjects. See PSOoGelf for restrictions.
$obj = [PSCustomObject] @{
    'customfield' = "abc"
    'facility' = "myNewFacilityForThisSpecificMessage"
}
Send-GLT_ErrorLog "Yikes!" $obj

# easy exception handling with emergency-level messages
try {
    throw "What The?!?"
}
catch {
    # pass the Error object. Boom, done!
    Send-GLT_ExceptionLog $_
    throw
}

# destroy hidden-in-memory data like the Gelf Server/Port... not really required.
Reset-GLT_Module

psglogthis's People

Contributors

intlbrendanber avatar sudobrendan avatar

Stargazers

 avatar Greg Hoelzer avatar

Watchers

Rob Wetzeler avatar James Cloos avatar Jeff Kolb avatar  avatar

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.