Code Monkey home page Code Monkey logo

Comments (3)

EsOsO avatar EsOsO commented on August 22, 2024

Hi @MCrank can you provide an example of the code you're having issue with?

from logging.

MCrank avatar MCrank commented on August 22, 2024

Sure thing. Here is my Configuration:

Set-LoggingDefaultLevel -Level $LogLevel
Add-LoggingLevel -Level 50 -LevelName SLACK
$ScriptName = [System.IO.Path]::GetFileNameWithoutExtension($MyInvocation.MyCommand.Name)

Add-LoggingTarget -Name File -Configuration @{
  Path = "$($PSScriptRoot)\Logs\$($env:COMPUTERNAME)_$($ScriptName)_%{+%Y%m%d}.log" 
}

Add-LoggingTarget -Name Slack -Configuration @{
  WebHook = "$env:NightlySlackURL"; 
  Level   = 'SLACK' 
}

So when I needed to send something critical that needs my attention to slack I would call it like this:

Write-Log -Level 'SLACK' -Message "Critical message goes here"

This would write the message to the Log file and send the message to slack as well. With the latest version my Write-Log statements would all get fired to the log and slack even when not targeting the SLACK logging level.

Otherwise I would just call Write-Log and set -Level to one of the default DEBUG, INFO, ERROR, etc to just output to the log file.

Here are the lines that used to handle this in Logging.psm1 I think.
https://github.com/EsOsO/Logging/blob/e62cd0b185588972bce7731c05aa9359effe456d/Logging/Logging.psm1#L102-L104

Oh and the version that I am using that works in this way is 2.7.2

from logging.

EsOsO avatar EsOsO commented on August 22, 2024

Hi @MCrank, since the introductions of defaults target configurations, the default target level doesn't honor the Set-LoggingDefaultLevel (I'll open an issue about that).

Right now you have to explicitly set the target level in the Add-LoggingTarget otherwise it will be set to NOTSET.

from logging.

Related Issues (20)

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.