diff --git a/src/Javinizer.build.ps1 b/src/Javinizer.build.ps1 index 10baffa1..7d2dd0d9 100644 --- a/src/Javinizer.build.ps1 +++ b/src/Javinizer.build.ps1 @@ -34,7 +34,7 @@ $ModuleName = (Split-Path -Path $BuildFile -Leaf).Split('.')[0] #Default Build $str = @() $str = 'Clean', 'ValidateRequirements' -#$str += 'FormattingCheck' +$str += 'FormattingCheck' $str += 'Analyze', 'Test', 'InfraTest' $str += 'Build', 'Archive' diff --git a/src/Javinizer/External/Logging/Logging.psd1 b/src/Javinizer/External/Logging/Logging.psd1 deleted file mode 100644 index 0a56d845..00000000 --- a/src/Javinizer/External/Logging/Logging.psd1 +++ /dev/null @@ -1,132 +0,0 @@ -# -# Module manifest for module 'PSGet_Logging' -# -# Generated by: Massimo Bonvicini -# -# Generated on: 10/01/2017 -# - -@{ - -# Script module or binary module file associated with this manifest. -RootModule = 'Logging.psm1' - -# Version number of this module. -ModuleVersion = '4.4.0' - -# Supported PSEditions -# CompatiblePSEditions = @() - -# ID used to uniquely identify this module -GUID = '25a60f1d-85dd-4ad6-9efc-35fd3894f6c1' - -# Author of this module -Author = 'Massimo Bonvicini' - -# Company or vendor of this module -CompanyName = 'Unknown' - -# Copyright statement for this module -Copyright = '(c) 2015 Massimo Bonvicini. All rights reserved.' - -# Description of the functionality provided by this module -Description = 'Powershell Logging Module' - -# Minimum version of the Windows PowerShell engine required by this module -# PowerShellVersion = '' - -# Name of the Windows PowerShell host required by this module -# PowerShellHostName = '' - -# Minimum version of the Windows PowerShell host required by this module -# PowerShellHostVersion = '' - -# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only. -# DotNetFrameworkVersion = '' - -# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only. -# CLRVersion = '' - -# Processor architecture (None, X86, Amd64) required by this module -# ProcessorArchitecture = '' - -# Modules that must be imported into the global environment prior to importing this module -# RequiredModules = @() - -# Assemblies that must be loaded prior to importing this module -# RequiredAssemblies = @() - -# Script files (.ps1) that are run in the caller's environment prior to importing this module. -# ScriptsToProcess = @() - -# Type files (.ps1xml) to be loaded when importing this module -# TypesToProcess = @() - -# Format files (.ps1xml) to be loaded when importing this module -# FormatsToProcess = @() - -# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess -# NestedModules = @() - -# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. -FunctionsToExport = @('Add-LoggingLevel','Add-LoggingTarget','Get-LoggingAvailableTarget','Get-LoggingCallerScope','Get-LoggingDefaultFormat','Get-LoggingDefaultLevel','Get-LoggingTarget','Set-LoggingCallerScope','Set-LoggingCustomTarget','Set-LoggingDefaultFormat','Set-LoggingDefaultLevel','Wait-Logging','Write-Log') - -# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. -CmdletsToExport = @() - -# Variables to export from this module -# VariablesToExport = @() - -# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export. -AliasesToExport = @() - -# DSC resources to export from this module -# DscResourcesToExport = @() - -# List of all modules packaged with this module -# ModuleList = @() - -# List of all files packaged with this module -# FileList = @() - -# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. -PrivateData = @{ - - PSData = @{ - - # Tags applied to this module. These help with module discovery in online galleries. - Tags = 'Logging','Log','Console','File','ElasticSearch','Slack','Email', 'Windows' - - # A URL to the license for this module. - LicenseUri = 'https://github.com/EsOsO/Logging/blob/master/docs/LICENSE' - - # A URL to the main website for this project. - ProjectUri = 'https://github.com/EsOsO/Logging' - - # A URL to an icon representing this module. - IconUri = 'https://github.com/EsOsO/Logging/blob/static/img/logo.svg' - - # ReleaseNotes of this module - ReleaseNotes = '' - - # External dependent modules of this module - # ExternalModuleDependencies = '' - - } # End of PSData hashtable - - } # End of PrivateData hashtable - -# HelpInfo URI of this module -HelpInfoURI = 'https://logging.readthedocs.io' - -# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. -# DefaultCommandPrefix = '' - -} - - - - - - - diff --git a/src/Javinizer/External/Logging/Logging.psm1 b/src/Javinizer/External/Logging/Logging.psm1 deleted file mode 100644 index 15a884fd..00000000 --- a/src/Javinizer/External/Logging/Logging.psm1 +++ /dev/null @@ -1,22 +0,0 @@ -$ScriptPath = Split-Path $MyInvocation.MyCommand.Path -$PSModule = $ExecutionContext.SessionState.Module -$PSModuleRoot = $PSModule.ModuleBase - -# Dot source public/private functions -$PublicFunctions = @(Get-ChildItem -Path "$SCriptPath\public" -Filter *.ps1 -Recurse -ErrorAction SilentlyContinue) -$PrivateFunctions = @(Get-ChildItem -Path "$SCriptPath\private" -Filter *.ps1 -Recurse -ErrorAction SilentlyContinue) - -$AllFunctions = $PublicFunctions + $PrivateFunctions -foreach ($Function in $AllFunctions) { - try { - . $Function.FullName - } catch { - throw ('Unable to dot source {0}' -f $Function.FullName) - } -} - -Export-ModuleMember -Function $PublicFunctions.BaseName - -Set-LoggingVariables - -Start-LoggingManager diff --git a/src/Javinizer/External/Logging/private/Get-LevelName.ps1 b/src/Javinizer/External/Logging/private/Get-LevelName.ps1 deleted file mode 100644 index 8c616ff1..00000000 --- a/src/Javinizer/External/Logging/private/Get-LevelName.ps1 +++ /dev/null @@ -1,10 +0,0 @@ -function Get-LevelName { - [CmdletBinding()] - param( - [int] $Level - ) - - $l = $Script:LevelNames[$Level] - if ($l) {return $l} - else {return ('Level {0}' -f $Level)} -} diff --git a/src/Javinizer/External/Logging/private/Get-LevelNumber.ps1 b/src/Javinizer/External/Logging/private/Get-LevelNumber.ps1 deleted file mode 100644 index bdc123c0..00000000 --- a/src/Javinizer/External/Logging/private/Get-LevelNumber.ps1 +++ /dev/null @@ -1,9 +0,0 @@ -function Get-LevelNumber { - [CmdletBinding()] - param( - $Level - ) - if ($Level -is [int] -and $Level -in $Script:LevelNames.Keys) {return $Level} - elseif ([string] $Level -eq $Level -and $Level -in $Script:LevelNames.Keys) {return $Script:LevelNames[$Level]} - else {throw ('Level not a valid integer or a valid string: {0}' -f $Level)} -} diff --git a/src/Javinizer/External/Logging/private/Get-LevelsName.ps1 b/src/Javinizer/External/Logging/private/Get-LevelsName.ps1 deleted file mode 100644 index 8c21a114..00000000 --- a/src/Javinizer/External/Logging/private/Get-LevelsName.ps1 +++ /dev/null @@ -1,6 +0,0 @@ -Function Get-LevelsName { - [CmdletBinding()] - param() - - return $Script:LevelNames.Keys | Where-Object {$_ -isnot [int]} | Sort-Object -} diff --git a/src/Javinizer/External/Logging/private/Initialize-LoggingTarget.ps1 b/src/Javinizer/External/Logging/private/Initialize-LoggingTarget.ps1 deleted file mode 100644 index 8d889c9a..00000000 --- a/src/Javinizer/External/Logging/private/Initialize-LoggingTarget.ps1 +++ /dev/null @@ -1,21 +0,0 @@ -function Initialize-LoggingTarget { - param() - - $targets = @() - $targets += Get-ChildItem "$ScriptRoot\targets" -Filter '*.ps1' - - if ((![String]::IsNullOrWhiteSpace($Script:Logging.CustomTargets)) -and (Test-Path -Path $Script:Logging.CustomTargets -PathType Container)) { - $targets += Get-ChildItem -Path $Script:Logging.CustomTargets -Filter '*.ps1' - } - - foreach ($target in $targets) { - $module = . $target.FullName - $Script:Logging.Targets[$module.Name] = @{ - Init = $module.Init - Logger = $module.Logger - Description = $module.Description - Defaults = $module.Configuration - ParamsRequired = $module.Configuration.GetEnumerator() | Where-Object {$_.Value.Required -eq $true} | Select-Object -ExpandProperty Name | Sort-Object - } - } -} diff --git a/src/Javinizer/External/Logging/private/Merge-DefaultConfig.ps1 b/src/Javinizer/External/Logging/private/Merge-DefaultConfig.ps1 deleted file mode 100644 index b58528d7..00000000 --- a/src/Javinizer/External/Logging/private/Merge-DefaultConfig.ps1 +++ /dev/null @@ -1,29 +0,0 @@ -function Merge-DefaultConfig { - param( - [string] $Target, - [hashtable] $Configuration - ) - - $DefaultConfiguration = $Script:Logging.Targets[$Target].Defaults - $ParamsRequired = $Script:Logging.Targets[$Target].ParamsRequired - - $result = @{} - - foreach ($Param in $DefaultConfiguration.Keys) { - if ($Param -in $ParamsRequired -and $Param -notin $Configuration.Keys) { - throw ('Configuration {0} is required for target {1}; please provide one of type {2}' -f $Param, $Target, $DefaultConfiguration[$Param].Type) - } - - if ($Configuration.ContainsKey($Param)) { - if ($Configuration[$Param] -is $DefaultConfiguration[$Param].Type) { - $result[$Param] = $Configuration[$Param] - } else { - throw ('Configuration {0} has to be of type {1} for target {2}' -f $Param, $DefaultConfiguration[$Param].Type, $Target) - } - } else { - $result[$Param] = $DefaultConfiguration[$Param].Default - } - } - - return $result -} diff --git a/src/Javinizer/External/Logging/private/New-LoggingDynamicParam.ps1 b/src/Javinizer/External/Logging/private/New-LoggingDynamicParam.ps1 deleted file mode 100644 index c4b70ae0..00000000 --- a/src/Javinizer/External/Logging/private/New-LoggingDynamicParam.ps1 +++ /dev/null @@ -1,88 +0,0 @@ -<# -.SYNOPSIS -Creates the param used inside the DynamicParam{}-Block - -.DESCRIPTION -New-LoggingDynamicParam creates (or appends) a RuntimeDefinedParameterDictionary -with a parameter whos value is validated through a dynamic validate set. - -.PARAMETER Name -displayed parameter name - -.PARAMETER Level -Constructs the validate set out of the currently configured logging level names. - -.PARAMETER Target -Constructs the validate set out of the currently configured logging targets. - -.PARAMETER DynamicParams -Dictionary to be appended. (Useful for multiple dynamic params) - -.PARAMETER Mandatory -Controls if parameter is mandatory for call. Defaults to $true - -.EXAMPLE -DynamicParam{ - New-LoggingDynamicParam -Name "Level" -Level -DefaultValue 'Verbose' -} - -DynamicParam{ - $dictionary = New-LoggingDynamicParam -Name "Level" -Level - New-LoggingDynamicParam -Name "Target" -Target -DynamicParams $dictionary -} -#> - -function New-LoggingDynamicParam { - [OutputType([System.Management.Automation.RuntimeDefinedParameterDictionary])] - [CmdletBinding(DefaultParameterSetName = "DynamicTarget")] - param( - [Parameter(Mandatory = $true, ParameterSetName = "DynamicLevel")] - [Parameter(Mandatory = $true, ParameterSetName = "DynamicTarget")] - [String] - $Name, - [Parameter(Mandatory = $true, ParameterSetName = "DynamicLevel")] - [switch] - $Level, - [Parameter(Mandatory = $true, ParameterSetName = "DynamicTarget")] - [switch] - $Target, - [boolean] - $Mandatory = $true, - [System.Management.Automation.RuntimeDefinedParameterDictionary] - $DynamicParams - ) - - if (!$DynamicParams) { - $DynamicParams = [System.Management.Automation.RuntimeDefinedParameterDictionary]::new() - } - - $attributeCollection = [System.Collections.ObjectModel.Collection[System.Attribute]]::new() - $attribute = [System.Management.Automation.ParameterAttribute]::new() - - $attribute.ParameterSetName = '__AllParameterSets' - $attribute.Mandatory = $Mandatory - $attribute.Position = 1 - - $attributeCollection.Add($attribute) - - - [String[]] $allowedValues = @() - - switch ($PSCmdlet.ParameterSetName) { - "DynamicTarget" { - $allowedValues += $Script:Logging.Targets.Keys - } - "DynamicLevel" { - $allowedValues += Get-LevelsName - } - } - - $validateSetAttribute = [System.Management.Automation.ValidateSetAttribute]::new($allowedValues) - $attributeCollection.Add($validateSetAttribute) - - $dynamicParam = [System.Management.Automation.RuntimeDefinedParameter]::new($Name, [string], $attributeCollection) - - $DynamicParams.Add($Name, $dynamicParam) - - return $DynamicParams -} \ No newline at end of file diff --git a/src/Javinizer/External/Logging/private/Replace-Token.ps1 b/src/Javinizer/External/Logging/private/Replace-Token.ps1 deleted file mode 100644 index f6829bef..00000000 --- a/src/Javinizer/External/Logging/private/Replace-Token.ps1 +++ /dev/null @@ -1,49 +0,0 @@ -function Replace-Token { - [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseApprovedVerbs', '')] - [CmdletBinding()] - param( - [string] $String, - [object] $Source - ) - - [string] $result = $String - [regex] $tokenMatcher = '%{(?\w+?)?(?::?\+(?(?:%[ABCDGHIMRSTUVWXYZabcdeghjklmnprstuwxy].*?)+))?(?::?\+(?(?:.*?)+))?(?::(?-?\d+))?}' - $tokenMatches = @() - $tokenMatches += $tokenMatcher.Matches($String) - - [array]::Reverse($tokenMatches) - - foreach ($match in $tokenMatches) { - $formattedEntry = [string]::Empty - $tokenContent = [string]::Empty - - $token = $match.Groups["token"].value - $datefmt = $match.Groups["datefmt"].value - $datefmtU = $match.Groups["datefmtU"].value - $padding = $match.Groups["padding"].value - - [hashtable] $dateParam = @{ } - if (-not [string]::IsNullOrWhiteSpace($token)) { - $tokenContent = $Source.$token - $dateParam["Date"] = $tokenContent - } - - if (-not [string]::IsNullOrWhiteSpace($datefmtU)) { - $formattedEntry = Get-Date @dateParam -UFormat $datefmtU - } - elseif (-not [string]::IsNullOrWhiteSpace($datefmt)) { - $formattedEntry = Get-Date @dateParam -Format $datefmt - } - else { - $formattedEntry = $tokenContent - } - - if ($padding) { - $formattedEntry = "{0,$padding}" -f $formattedEntry - } - - $result = $result.Substring(0, $match.Index) + $formattedEntry + $result.Substring($match.Index + $match.Length) - } - - return $result -} \ No newline at end of file diff --git a/src/Javinizer/External/Logging/private/Set-LoggingVariables.ps1 b/src/Javinizer/External/Logging/private/Set-LoggingVariables.ps1 deleted file mode 100644 index 219d0112..00000000 --- a/src/Javinizer/External/Logging/private/Set-LoggingVariables.ps1 +++ /dev/null @@ -1,47 +0,0 @@ -function Set-LoggingVariables { - - #Already setup - if ($Script:Logging -and $Script:LevelNames) { - return - } - - Write-Verbose -Message 'Setting up vars' - - $Script:NOTSET = 0 - $Script:DEBUG = 10 - $Script:INFO = 20 - $Script:WARNING = 30 - $Script:ERROR_ = 40 - - New-Variable -Name LevelNames -Scope Script -Option ReadOnly -Value ([hashtable]::Synchronized(@{ - $NOTSET = 'NOTSET' - $ERROR_ = 'ERROR' - $WARNING = 'WARNING' - $INFO = 'INFO' - $DEBUG = 'DEBUG' - 'NOTSET' = $NOTSET - 'ERROR' = $ERROR_ - 'WARNING' = $WARNING - 'INFO' = $INFO - 'DEBUG' = $DEBUG - })) - - New-Variable -Name ScriptRoot -Scope Script -Option ReadOnly -Value ([System.IO.Path]::GetDirectoryName($MyInvocation.MyCommand.Module.Path)) - New-Variable -Name Defaults -Scope Script -Option ReadOnly -Value @{ - Level = $LevelNames[$LevelNames['NOTSET']] - LevelNo = $LevelNames['NOTSET'] - Format = '[%{timestamp:+%Y-%m-%d %T%Z}] [%{level:-7}] %{message}' - Timestamp = '%Y-%m-%dT%T%Z' - CallerScope = 1 - } - - New-Variable -Name Logging -Scope Script -Option ReadOnly -Value ([hashtable]::Synchronized(@{ - Level = $Defaults.Level - LevelNo = $Defaults.LevelNo - Format = $Defaults.Format - CallerScope = $Defaults.CallerScope - CustomTargets = [String]::Empty - Targets = ([System.Collections.Concurrent.ConcurrentDictionary[string, hashtable]]::new([System.StringComparer]::OrdinalIgnoreCase)) - EnabledTargets = ([System.Collections.Concurrent.ConcurrentDictionary[string, hashtable]]::new([System.StringComparer]::OrdinalIgnoreCase)) - })) -} \ No newline at end of file diff --git a/src/Javinizer/External/Logging/private/Start-LoggingManager.ps1 b/src/Javinizer/External/Logging/private/Start-LoggingManager.ps1 deleted file mode 100644 index f41541c3..00000000 --- a/src/Javinizer/External/Logging/private/Start-LoggingManager.ps1 +++ /dev/null @@ -1,102 +0,0 @@ -function Start-LoggingManager { - [CmdletBinding()] - param( - [TimeSpan]$ConsumerStartupTimeout = "00:00:10" - ) - - New-Variable -Name LoggingEventQueue -Scope Script -Value ([System.Collections.Concurrent.BlockingCollection[hashtable]]::new(100)) - New-Variable -Name LoggingRunspace -Scope Script -Option ReadOnly -Value ([hashtable]::Synchronized(@{ })) - New-Variable -Name TargetsInitSync -Scope Script -Option ReadOnly -Value ([System.Threading.ManualResetEventSlim]::new($false)) - - $Script:InitialSessionState = [initialsessionstate]::CreateDefault() - - if ($Script:InitialSessionState.psobject.Properties['ApartmentState']) { - $Script:InitialSessionState.ApartmentState = [System.Threading.ApartmentState]::MTA - } - - # Importing variables into runspace - foreach ($sessionVariable in 'ScriptRoot', 'LevelNames', 'Logging', 'LoggingEventQueue', 'TargetsInitSync') { - $Value = Get-Variable -Name $sessionVariable -ErrorAction Continue -ValueOnly - Write-Verbose "Importing variable $sessionVariable`: $Value into runspace" - $v = New-Object System.Management.Automation.Runspaces.SessionStateVariableEntry -ArgumentList $sessionVariable, $Value, '', ([System.Management.Automation.ScopedItemOptions]::AllScope) - $Script:InitialSessionState.Variables.Add($v) - } - - # Importing functions into runspace - foreach ($Function in 'Replace-Token', 'Initialize-LoggingTarget', 'Get-LevelNumber') { - Write-Verbose "Importing function $($Function) into runspace" - $Body = Get-Content Function:\$Function - $f = New-Object System.Management.Automation.Runspaces.SessionStateFunctionEntry -ArgumentList $Function, $Body - $Script:InitialSessionState.Commands.Add($f) - } - - #Setup runspace - $Script:LoggingRunspace.Runspace = [runspacefactory]::CreateRunspace($Script:InitialSessionState) - $Script:LoggingRunspace.Runspace.Name = 'LoggingQueueConsumer' - $Script:LoggingRunspace.Runspace.Open() - $Script:LoggingRunspace.Runspace.SessionStateProxy.SetVariable('ParentHost', $Host) - $Script:LoggingRunspace.Runspace.SessionStateProxy.SetVariable('VerbosePreference', $VerbosePreference) - - # Spawn Logging Consumer - $Consumer = { - Initialize-LoggingTarget - - $TargetsInitSync.Set(); # Signal to the parent runspace that logging targets have been loaded - - foreach ($Log in $Script:LoggingEventQueue.GetConsumingEnumerable()) { - if ($Script:Logging.EnabledTargets) { - $ParentHost.NotifyBeginApplication() - - try { - #Enumerating through a collection is intrinsically not a thread-safe procedure - for ($targetEnum = $Script:Logging.EnabledTargets.GetEnumerator(); $targetEnum.MoveNext(); ) { - [string] $LoggingTarget = $targetEnum.Current.key - [hashtable] $TargetConfiguration = $targetEnum.Current.Value - $Logger = [scriptblock] $Script:Logging.Targets[$LoggingTarget].Logger - - $targetLevelNo = Get-LevelNumber -Level $TargetConfiguration.Level - - if ($Log.LevelNo -ge $targetLevelNo) { - Invoke-Command -ScriptBlock $Logger -ArgumentList @($Log, $TargetConfiguration) - } - } - } - catch { - $ParentHost.UI.WriteErrorLine($_) - } - finally { - $ParentHost.NotifyEndApplication() - } - } - } - } - - $Script:LoggingRunspace.Powershell = [Powershell]::Create().AddScript($Consumer, $true) - $Script:LoggingRunspace.Powershell.Runspace = $Script:LoggingRunspace.Runspace - $Script:LoggingRunspace.Handle = $Script:LoggingRunspace.Powershell.BeginInvoke() - - #region Handle Module Removal - $OnRemoval = { - $Module = Get-Module Logging - - if ($Module) { - $Module.Invoke({ - Wait-Logging - Stop-LoggingManager - }) - } - - [System.GC]::Collect() - } - - # This scriptblock would be called within the module scope - $ExecutionContext.SessionState.Module.OnRemove += $OnRemoval - - # This scriptblock would be called within the global scope and wouldn't have access to internal module variables and functions that we need - $Script:LoggingRunspace.EngineEventJob = Register-EngineEvent -SourceIdentifier ([System.Management.Automation.PsEngineEvent]::Exiting) -Action $OnRemoval - #endregion Handle Module Removal - - if(-not $TargetsInitSync.Wait($ConsumerStartupTimeout)){ - throw 'Timed out while waiting for logging consumer to start up' - } -} \ No newline at end of file diff --git a/src/Javinizer/External/Logging/private/Stop-LoggingManager.ps1 b/src/Javinizer/External/Logging/private/Stop-LoggingManager.ps1 deleted file mode 100644 index a1e26f45..00000000 --- a/src/Javinizer/External/Logging/private/Stop-LoggingManager.ps1 +++ /dev/null @@ -1,16 +0,0 @@ -function Stop-LoggingManager { - param () - - $Script:LoggingEventQueue.CompleteAdding() - $Script:LoggingEventQueue.Dispose() - - [void] $Script:LoggingRunspace.Powershell.EndInvoke($Script:LoggingRunspace.Handle) - [void] $Script:LoggingRunspace.Powershell.Dispose() - - $ExecutionContext.SessionState.Module.OnRemove = $null - Get-EventSubscriber | Where-Object { $_.Action.Id -eq $Script:LoggingRunspace.EngineEventJob.Id } | Unregister-Event - - Remove-Variable -Scope Script -Force -Name LoggingEventQueue - Remove-Variable -Scope Script -Force -Name LoggingRunspace - Remove-Variable -Scope Script -Force -Name TargetsInitSync -} \ No newline at end of file diff --git a/src/Javinizer/External/Logging/public/Add-LoggingLevel.ps1 b/src/Javinizer/External/Logging/public/Add-LoggingLevel.ps1 deleted file mode 100644 index 508887d0..00000000 --- a/src/Javinizer/External/Logging/public/Add-LoggingLevel.ps1 +++ /dev/null @@ -1,55 +0,0 @@ -<# - .SYNOPSIS - Define a new severity level - - .DESCRIPTION - This function add a new severity level to the ones already defined - - .PARAMETER Level - An integer that identify the severity of the level, higher the value higher the severity of the level - By default the module defines this levels: - NOTSET 0 - DEBUG 10 - INFO 20 - WARNING 30 - ERROR 40 - - .PARAMETER LevelName - The human redable name to assign to the level - - .EXAMPLE - PS C:\> Add-LoggingLevel -Level 41 -LevelName CRITICAL - - .EXAMPLE - PS C:\> Add-LoggingLevel -Level 15 -LevelName VERBOSE - - .LINK - https://logging.readthedocs.io/en/latest/functions/Add-LoggingLevel.md - - .LINK - https://logging.readthedocs.io/en/latest/functions/Write-Log.md - - .LINK - https://github.com/EsOsO/Logging/blob/master/Logging/public/Add-LoggingLevel.ps1 -#> -function Add-LoggingLevel { - [CmdletBinding(HelpUri='https://logging.readthedocs.io/en/latest/functions/Add-LoggingLevel.md')] - param( - [Parameter(Mandatory)] - [int] $Level, - [Parameter(Mandatory)] - [string] $LevelName - ) - - if ($Level -notin $LevelNames.Keys -and $LevelName -notin $LevelNames.Keys) { - $LevelNames[$Level] = $LevelName.ToUpper() - $LevelNames[$LevelName] = $Level - } elseif ($Level -in $LevelNames.Keys -and $LevelName -notin $LevelNames.Keys) { - $LevelNames.Remove($LevelNames[$Level]) | Out-Null - $LevelNames[$Level] = $LevelName.ToUpper() - $LevelNames[$LevelNames[$Level]] = $Level - } elseif ($Level -notin $LevelNames.Keys -and $LevelName -in $LevelNames.Keys) { - $LevelNames.Remove($LevelNames[$LevelName]) | Out-Null - $LevelNames[$LevelName] = $Level - } -} diff --git a/src/Javinizer/External/Logging/public/Add-LoggingTarget.ps1 b/src/Javinizer/External/Logging/public/Add-LoggingTarget.ps1 deleted file mode 100644 index e198cc3b..00000000 --- a/src/Javinizer/External/Logging/public/Add-LoggingTarget.ps1 +++ /dev/null @@ -1,49 +0,0 @@ -<# - .SYNOPSIS - Enable a logging target - .DESCRIPTION - This function configure and enable a logging target - .PARAMETER Name - The name of the target to enable and configure - .PARAMETER Configuration - An hashtable containing the configurations for the target - .EXAMPLE - PS C:\> Add-LoggingTarget -Name Console -Configuration @{Level = 'DEBUG'} - .EXAMPLE - PS C:\> Add-LoggingTarget -Name File -Configuration @{Level = 'INFO'; Path = 'C:\Temp\script.log'} - .LINK - https://logging.readthedocs.io/en/latest/functions/Add-LoggingTarget.md - .LINK - https://logging.readthedocs.io/en/latest/functions/Write-Log.md - .LINK - https://logging.readthedocs.io/en/latest/AvailableTargets.md - .LINK - https://github.com/EsOsO/Logging/blob/master/Logging/public/Add-LoggingTarget.ps1 -#> -function Add-LoggingTarget { - [CmdletBinding(HelpUri='https://logging.readthedocs.io/en/latest/functions/Add-LoggingTarget.md')] - param( - [Parameter(Position = 2)] - [hashtable] $Configuration = @{} - ) - - DynamicParam { - New-LoggingDynamicParam -Name 'Name' -Target - } - - End { - $Script:Logging.EnabledTargets[$PSBoundParameters.Name] = Merge-DefaultConfig -Target $PSBoundParameters.Name -Configuration $Configuration - - # Special case hack - resolve target file path if it's a relative path - # This can't be done in the Init scriptblock of the logging target because that scriptblock gets created in the - # log consumer runspace and doesn't inherit the current SessionState. That means that the scriptblock doesn't know the - # current working directory at the time when `Add-LoggingTarget` is being called and can't accurately resolve the relative path. - if($PSBoundParameters.Name -eq 'File'){ - $Script:Logging.EnabledTargets[$PSBoundParameters.Name].Path = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Configuration.Path) - } - - if ($Script:Logging.Targets[$PSBoundParameters.Name].Init -is [scriptblock]) { - & $Script:Logging.Targets[$PSBoundParameters.Name].Init $Configuration - } - } -} \ No newline at end of file diff --git a/src/Javinizer/External/Logging/public/Get-LoggingAvailableTarget.ps1 b/src/Javinizer/External/Logging/public/Get-LoggingAvailableTarget.ps1 deleted file mode 100644 index 32b1548a..00000000 --- a/src/Javinizer/External/Logging/public/Get-LoggingAvailableTarget.ps1 +++ /dev/null @@ -1,20 +0,0 @@ -<# - .SYNOPSIS - Returns available logging targets - .DESCRIPTION - This function returns available logging targtes - .EXAMPLE - PS C:\> Get-LoggingAvailableTarget - .LINK - https://logging.readthedocs.io/en/latest/functions/Get-LoggingAvailableTarget.md - .LINK - https://logging.readthedocs.io/en/latest/functions/Write-Log.md - .LINK - https://github.com/EsOsO/Logging/blob/master/Logging/public/Get-LoggingAvailableTarget.ps1 -#> -function Get-LoggingAvailableTarget { - [CmdletBinding(HelpUri='https://logging.readthedocs.io/en/latest/functions/Get-LoggingAvailableTarget.md')] - param() - - return $Script:Logging.Targets -} \ No newline at end of file diff --git a/src/Javinizer/External/Logging/public/Get-LoggingCallerScope.ps1 b/src/Javinizer/External/Logging/public/Get-LoggingCallerScope.ps1 deleted file mode 100644 index 0051dfd2..00000000 --- a/src/Javinizer/External/Logging/public/Get-LoggingCallerScope.ps1 +++ /dev/null @@ -1,22 +0,0 @@ -<# - .SYNOPSIS - Returns the default caller scope - .DESCRIPTION - This function returns an int representing the scope where the invocation scope for the caller should be obtained from - .EXAMPLE - PS C:\> Get-LoggingCallerScope - .LINK - https://logging.readthedocs.io/en/latest/functions/Get-LoggingCallerScope.md - .LINK - https://logging.readthedocs.io/en/latest/functions/Write-Log.md - .LINK - https://logging.readthedocs.io/en/latest/LoggingFormat.md - .LINK - https://github.com/EsOsO/Logging/blob/master/Logging/public/Get-LoggingCallerScope.ps1 -#> -function Get-LoggingCallerScope { - [CmdletBinding()] - param() - - return $Script:Logging.CallerScope -} \ No newline at end of file diff --git a/src/Javinizer/External/Logging/public/Get-LoggingDefaultFormat.ps1 b/src/Javinizer/External/Logging/public/Get-LoggingDefaultFormat.ps1 deleted file mode 100644 index e000f95b..00000000 --- a/src/Javinizer/External/Logging/public/Get-LoggingDefaultFormat.ps1 +++ /dev/null @@ -1,22 +0,0 @@ -<# - .SYNOPSIS - Returns the default message format - .DESCRIPTION - This function returns a string representing the default message format used by enabled targets that don't override it - .EXAMPLE - PS C:\> Get-LoggingDefaultFormat - .LINK - https://logging.readthedocs.io/en/latest/functions/Get-LoggingDefaultFormat.md - .LINK - https://logging.readthedocs.io/en/latest/functions/Write-Log.md - .LINK - https://logging.readthedocs.io/en/latest/LoggingFormat.md - .LINK - https://github.com/EsOsO/Logging/blob/master/Logging/public/Get-LoggingDefaultFormat.ps1 -#> -function Get-LoggingDefaultFormat { - [CmdletBinding()] - param() - - return $Script:Logging.Format -} \ No newline at end of file diff --git a/src/Javinizer/External/Logging/public/Get-LoggingDefaultLevel.ps1 b/src/Javinizer/External/Logging/public/Get-LoggingDefaultLevel.ps1 deleted file mode 100644 index c160a214..00000000 --- a/src/Javinizer/External/Logging/public/Get-LoggingDefaultLevel.ps1 +++ /dev/null @@ -1,25 +0,0 @@ -<# - .SYNOPSIS - Returns the default message level - - .DESCRIPTION - This function returns a string representing the default message level used by enabled targets that don't override it - - .EXAMPLE - PS C:\> Get-LoggingDefaultLevel - - .LINK - https://logging.readthedocs.io/en/latest/functions/Get-LoggingDefaultLevel.md - - .LINK - https://logging.readthedocs.io/en/latest/functions/Write-Log.md - - .LINK - https://github.com/EsOsO/Logging/blob/master/Logging/public/Get-LoggingDefaultLevel.ps1 -#> -function Get-LoggingDefaultLevel { - [CmdletBinding(HelpUri = 'https://logging.readthedocs.io/en/latest/functions/Get-LoggingDefaultLevel.md')] - param() - - return Get-LevelName -Level $Script:Logging.LevelNo -} diff --git a/src/Javinizer/External/Logging/public/Get-LoggingTarget.ps1 b/src/Javinizer/External/Logging/public/Get-LoggingTarget.ps1 deleted file mode 100644 index 81f3d497..00000000 --- a/src/Javinizer/External/Logging/public/Get-LoggingTarget.ps1 +++ /dev/null @@ -1,30 +0,0 @@ -<# - .SYNOPSIS - Returns enabled logging targets - .DESCRIPTION - This function returns enabled logging targtes - .PARAMETER Name - The Name of the target to retrieve, if not passed all configured targets will be returned - .EXAMPLE - PS C:\> Get-LoggingTarget - .EXAMPLE - PS C:\> Get-LoggingTarget -Name Console - .LINK - https://logging.readthedocs.io/en/latest/functions/Get-LoggingTarget.md - .LINK - https://logging.readthedocs.io/en/latest/functions/Write-Log.md - .LINK - https://github.com/EsOsO/Logging/blob/master/Logging/public/Get-LoggingTarget.ps1 -#> -function Get-LoggingTarget { - [CmdletBinding(HelpUri = 'https://logging.readthedocs.io/en/latest/functions/Get-LoggingTarget.md')] - param( - [string] $Name = $null - ) - - if ($PSBoundParameters.Name) { - return $Script:Logging.EnabledTargets[$Name] - } - - return $Script:Logging.EnabledTargets -} diff --git a/src/Javinizer/External/Logging/public/Set-LoggingCallerScope.ps1 b/src/Javinizer/External/Logging/public/Set-LoggingCallerScope.ps1 deleted file mode 100644 index 68b7b8d1..00000000 --- a/src/Javinizer/External/Logging/public/Set-LoggingCallerScope.ps1 +++ /dev/null @@ -1,36 +0,0 @@ -<# - .SYNOPSIS - Sets the scope from which to get the caller scope - - .DESCRIPTION - This function sets the scope to obtain information from the caller - - .PARAMETER CallerScope - Integer representing the scope to use to find the caller information. Defaults to 1 which represent the scope of the function where Write-Log is being called from - - .EXAMPLE - PS C:\> Set-LoggingCallerScope -CallerScope 2 - - .EXAMPLE - PS C:\> Set-LoggingCallerScope - - It sets the caller scope to 1 - - .LINK - https://logging.readthedocs.io/en/latest/functions/Set-LoggingCallerScope.md - - .LINK - https://logging.readthedocs.io/en/latest/functions/Write-Log.md - - .LINK - https://github.com/EsOsO/Logging/blob/master/Logging/public/Set-LoggingCallerScope.ps1 -#> -function Set-LoggingCallerScope { - [CmdletBinding(HelpUri='https://logging.readthedocs.io/en/latest/functions/Set-LoggingCallerScope.md')] - param( - [int]$CallerScope = $Defaults.CallerScope - ) - - Wait-Logging - $Script:Logging.CallerScope = $CallerScope -} diff --git a/src/Javinizer/External/Logging/public/Set-LoggingCustomTarget.ps1 b/src/Javinizer/External/Logging/public/Set-LoggingCustomTarget.ps1 deleted file mode 100644 index 0a3f7372..00000000 --- a/src/Javinizer/External/Logging/public/Set-LoggingCustomTarget.ps1 +++ /dev/null @@ -1,42 +0,0 @@ -<# - .SYNOPSIS - Sets a folder as custom target repository - - .DESCRIPTION - This function sets a folder as a custom target repository. - Every *.ps1 file will be loaded as a custom target and available to be enabled for logging to. - - .PARAMETER Path - A valid path containing *.ps1 files that defines new loggin targets - - .EXAMPLE - PS C:\> Set-LoggingCustomTarget -Path C:\Logging\CustomTargets - - .LINK - https://logging.readthedocs.io/en/latest/functions/Set-LoggingCustomTarget.md - - .LINK - https://logging.readthedocs.io/en/latest/functions/CustomTargets.md - - .LINK - https://logging.readthedocs.io/en/latest/functions/Write-Log.md - - .LINK - https://github.com/EsOsO/Logging/blob/master/Logging/public/Set-LoggingCustomTarget.ps1 -#> -function Set-LoggingCustomTarget { - [CmdletBinding(HelpUri='https://logging.readthedocs.io/en/latest/functions/Set-LoggingCustomTarget.md')] - param( - [Parameter(Mandatory)] - [ValidateScript({Test-Path -Path $_ -PathType Container})] - [string] $Path - ) - - Write-Verbose 'Stopping Logging Manager' - Stop-LoggingManager - - $Script:Logging.CustomTargets = $Path - - Write-Verbose 'Starting Logging Manager' - Start-LoggingManager -} diff --git a/src/Javinizer/External/Logging/public/Set-LoggingDefaultFormat.ps1 b/src/Javinizer/External/Logging/public/Set-LoggingDefaultFormat.ps1 deleted file mode 100644 index 8e318663..00000000 --- a/src/Javinizer/External/Logging/public/Set-LoggingDefaultFormat.ps1 +++ /dev/null @@ -1,53 +0,0 @@ -<# - .SYNOPSIS - Sets a global logging message format - - .DESCRIPTION - This function sets a global logging message format - - .PARAMETER Format - The string used to format the message to log - - .EXAMPLE - PS C:\> Set-LoggingDefaultFormat -Format '[%{level:-7}] %{message}' - - .EXAMPLE - PS C:\> Set-LoggingDefaultFormat - - It sets the default format as [%{timestamp:+%Y-%m-%d %T%Z}] [%{level:-7}] %{message} - - .LINK - https://logging.readthedocs.io/en/latest/functions/Set-LoggingDefaultFormat.md - - .LINK - https://logging.readthedocs.io/en/latest/functions/LoggingFormat.md - - .LINK - https://logging.readthedocs.io/en/latest/functions/Write-Log.md - - .LINK - https://github.com/EsOsO/Logging/blob/master/Logging/public/Set-LoggingDefaultFormat.ps1 -#> -function Set-LoggingDefaultFormat { - [CmdletBinding(HelpUri='https://logging.readthedocs.io/en/latest/functions/Set-LoggingDefaultFormat.md')] - param( - [string] $Format = $Defaults.Format - ) - - Wait-Logging - $Script:Logging.Format = $Format - - # Setting format on already configured targets - foreach ($Target in $Script:Logging.EnabledTargets.Values) { - if ($Target.ContainsKey('Format')) { - $Target['Format'] = $Script:Logging.Format - } - } - - # Setting format on available targets - foreach ($Target in $Script:Logging.Targets.Values) { - if ($Target.Defaults.ContainsKey('Format')) { - $Target.Defaults.Format.Default = $Script:Logging.Format - } - } -} diff --git a/src/Javinizer/External/Logging/public/Set-LoggingDefaultLevel.ps1 b/src/Javinizer/External/Logging/public/Set-LoggingDefaultLevel.ps1 deleted file mode 100644 index 151a126f..00000000 --- a/src/Javinizer/External/Logging/public/Set-LoggingDefaultLevel.ps1 +++ /dev/null @@ -1,53 +0,0 @@ -<# - .SYNOPSIS - Sets a global logging severity level. - - .DESCRIPTION - This function sets a global logging severity level. - Log messages written with a lower logging level will be discarded. - - .PARAMETER Level - The level severity name to set as default for enabled targets - - .EXAMPLE - PS C:\> Set-LoggingDefaultLevel -Level ERROR - - PS C:\> Write-Log -Level INFO -Message "Test" - => Discarded. - - .LINK - https://logging.readthedocs.io/en/latest/functions/Set-LoggingDefaultLevel.md - - .LINK - https://logging.readthedocs.io/en/latest/functions/Write-Log.md - - .LINK - https://github.com/EsOsO/Logging/blob/master/Logging/public/Set-LoggingDefaultLevel.ps1 -#> -function Set-LoggingDefaultLevel { - [CmdletBinding(HelpUri = 'https://logging.readthedocs.io/en/latest/functions/Set-LoggingDefaultLevel.md')] - param() - - DynamicParam { - New-LoggingDynamicParam -Name "Level" -Level - } - - End { - $Script:Logging.Level = $PSBoundParameters.Level - $Script:Logging.LevelNo = Get-LevelNumber -Level $PSBoundParameters.Level - - # Setting level on already configured targets - foreach ($Target in $Script:Logging.EnabledTargets.Values) { - if ($Target.ContainsKey('Level')) { - $Target['Level'] = $Script:Logging.Level - } - } - - # Setting level on available targets - foreach ($Target in $Script:Logging.Targets.Values) { - if ($Target.Defaults.ContainsKey('Level')) { - $Target.Defaults.Level.Default = $Script:Logging.Level - } - } - } -} diff --git a/src/Javinizer/External/Logging/public/Wait-Logging.ps1 b/src/Javinizer/External/Logging/public/Wait-Logging.ps1 deleted file mode 100644 index 253d5aac..00000000 --- a/src/Javinizer/External/Logging/public/Wait-Logging.ps1 +++ /dev/null @@ -1,43 +0,0 @@ -<# - .SYNOPSIS - Wait for the message queue to be emptied - - .DESCRIPTION - This function can be used to block the execution of a script waiting for the message queue to be emptied - - .EXAMPLE - PS C:\> Wait-Logging - - .LINK - https://logging.readthedocs.io/en/latest/functions/Wait-Logging.md - - .LINK - https://github.com/EsOsO/Logging/blob/master/Logging/public/Wait-Logging.ps1 -#> -function Wait-Logging { - [CmdletBinding(HelpUri='https://logging.readthedocs.io/en/latest/functions/Wait-Logging.md')] - param() - - #This variable is initiated inside Start-LoggingManager - if (!(Get-Variable -Name "LoggingEventQueue" -ErrorAction Ignore)) { - return - } - - $start = [datetime]::Now - - Start-Sleep -Milliseconds 10 - - while ($Script:LoggingEventQueue.Count -gt 0) { - Start-Sleep -Milliseconds 20 - - <# - If errors occure in the consumption of the logging requests, - forcefully shutdown function after some time. - #> - $difference = [datetime]::Now - $start - if ($difference.seconds -gt 30) { - Write-Error -Message ("{0} :: Wait timeout." -f $MyInvocation.MyCommand) -ErrorAction SilentlyContinue - break; - } - } -} diff --git a/src/Javinizer/External/Logging/public/Write-Log.ps1 b/src/Javinizer/External/Logging/public/Write-Log.ps1 deleted file mode 100644 index 710eae7d..00000000 --- a/src/Javinizer/External/Logging/public/Write-Log.ps1 +++ /dev/null @@ -1,102 +0,0 @@ -<# - .SYNOPSIS - Emits a log record - - .DESCRIPTION - This function write a log record to configured targets with the matching level - - .PARAMETER Level - The log level of the message. Valid values are DEBUG, INFO, WARNING, ERROR, NOTSET - Other custom levels can be added and are a valid value for the parameter - INFO is the default - - .PARAMETER Message - The text message to write - - .PARAMETER Arguments - An array of objects used to format - - .PARAMETER Body - An object that can contain additional log metadata (used in target like ElasticSearch) - - .PARAMETER ExceptionInfo - An optional ErrorRecord - - .EXAMPLE - PS C:\> Write-Log 'Hello, World!' - - .EXAMPLE - PS C:\> Write-Log -Level ERROR -Message 'Hello, World!' - - .EXAMPLE - PS C:\> Write-Log -Level ERROR -Message 'Hello, {0}!' -Arguments 'World' - - .EXAMPLE - PS C:\> Write-Log -Level ERROR -Message 'Hello, {0}!' -Arguments 'World' -Body @{Server='srv01.contoso.com'} - - .LINK - https://logging.readthedocs.io/en/latest/functions/Write-Log.md - - .LINK - https://logging.readthedocs.io/en/latest/functions/Add-LoggingLevel.md - - .LINK - https://github.com/EsOsO/Logging/blob/master/Logging/public/Write-Log.ps1 -#> -Function Write-Log { - [CmdletBinding()] - param( - [Parameter(Position = 2, - Mandatory = $true)] - [string] $Message, - [Parameter(Position = 3, - Mandatory = $false)] - [array] $Arguments, - [Parameter(Position = 4, - Mandatory = $false)] - [object] $Body = $null, - [Parameter(Position = 5, - Mandatory = $false)] - [System.Management.Automation.ErrorRecord] $ExceptionInfo = $null - ) - - DynamicParam { - New-LoggingDynamicParam -Level -Mandatory $false -Name "Level" - $PSBoundParameters["Level"] = "INFO" - } - - End { - [string] $messageText = $Message - - if ($PSBoundParameters.ContainsKey('Arguments')) { - $messageText = $messageText -f $Arguments - } - - $levelNumber = Get-LevelNumber -Level $PSBoundParameters.Level - $invocationInfo = (Get-PSCallStack)[$Script:Logging.CallerScope] - - # Split-Path throws an exception if called with a -Path that is null or empty. - [string] $fileName = [string]::Empty - if (-not [string]::IsNullOrEmpty($invocationInfo.ScriptName)) { - $fileName = Split-Path -Path $invocationInfo.ScriptName -Leaf - } - - $logMessage = [hashtable] @{ - timestamp = Get-Date -UFormat $Defaults.Timestamp - timestamputc = Get-Date ([datetime]::UtcNow) -UFormat $Defaults.Timestamp - level = Get-LevelName -Level $levelNumber - levelno = $levelNumber - lineno = $invocationInfo.ScriptLineNumber - pathname = $invocationInfo.ScriptName - filename = $fileName - caller = $invocationInfo.Command - message = $messageText - body = $Body - execinfo = $ExceptionInfo - pid = $PID - } - - #This variable is initiated via Start-LoggingManager - $Script:LoggingEventQueue.Add($logMessage) - } -} diff --git a/src/Javinizer/External/Logging/targets/AzureLogAnalytics.ps1 b/src/Javinizer/External/Logging/targets/AzureLogAnalytics.ps1 deleted file mode 100644 index 22178a57..00000000 --- a/src/Javinizer/External/Logging/targets/AzureLogAnalytics.ps1 +++ /dev/null @@ -1,100 +0,0 @@ -@{ - Name = 'AzureLogAnalytics' - Description = 'Sends log data to a Azure Log Analytics Workspace' - Configuration = @{ - WorkspaceId = @{Required = $true; Type = [string]; Default = $null } - SharedKey = @{Required = $true; Type = [string]; Default = $null } - LogType = @{Required = $false; Type = [string]; Default = "Logging" } - Level = @{Required = $false; Type = [string]; Default = $Logging.Level } - } - Logger = { - param( - [hashtable] $Log, - [hashtable] $Configuration - ) - - Function GetAuthorizationSignature { - [CmdletBinding()] - param ( - $WorkspaceId, - $SharedKey, - $Hashable - ) - - $hashableBytes = [Text.Encoding]::UTF8.GetBytes($Hashable) - $key = [Convert]::FromBase64String($SharedKey) - $sha256 = New-Object System.Security.Cryptography.HMACSHA256 - $sha256.Key = $key - $hash = $sha256.ComputeHash($hashableBytes) - $authorization = 'SharedKey {0}:{1}' -f $WorkspaceId, - [Convert]::ToBase64String($hash) - - return $authorization - } - - Function WriteLogAnalyticsData { - param ( - $WorkspaceId, - $SharedKey, - $LogType, - $Body - ) - $method = "POST" - $contentType = "application/json" - $resource = "/api/logs" - $contentLength = $Body.Length - $rfc1123date = [DateTime]::UtcNow.ToString("r") - $xHeaders = "x-ms-date:" + $rfc1123date - - $hashable = $method, $contentLength, $contentType, $xHeaders, $resource -join "`n" - $getAuthorizationSignatureSplat = @{ - - WorkspaceId = $WorkspaceId - SharedKey = $SharedKey - Hashable = $hashable - } - $authorization = GetAuthorizationSignature @getAuthorizationSignatureSplat - $uri = "https://${WorkspaceId}.ods.opinsights.azure.com${resource}?api-version=2016-04-01" - - $headers = @{ - - Authorization = $authorization - 'Log-Type' = $LogType - 'x-ms-date' = $rfc1123date - 'time-generated-field' = 'timestamputc' - } - - $invokeWebRequestSplat = @{ - - Uri = $uri - Method = $method - ContentType = $contentType - Headers = $headers - Body = $Body - UseBasicParsing = $true - } - Invoke-WebRequest @invokeWebRequestSplat - } - - # Convert timestamp from utc to ISO 8601 - $Log.timestamputc = $Log.timestamputc | Get-Date -UFormat '+%Y-%m-%dT%H:%M:%S.000Z' - - # See if a Body was provided, that needs to be expanded. - if ($Log.Body) { - $Log = $Log + $Log.Body - $Log.Remove('Body') - } - - # Submit the data to the API endpoint - $json = $Log | ConvertTo-Json - $encodedJson = [System.Text.Encoding]::UTF8.GetBytes($json) - $writeLogAnalyticsDataSplat = @{ - - WorkspaceId = $Configuration.'WorkspaceId' - SharedKey = $Configuration.'SharedKey' - LogType = $Configuration.'LogType' - Body = $encodedJson - } - $null = WriteLogAnalyticsData @writeLogAnalyticsDataSplat - } -} \ No newline at end of file diff --git a/src/Javinizer/External/Logging/targets/Console.ps1 b/src/Javinizer/External/Logging/targets/Console.ps1 deleted file mode 100644 index ebb5a76e..00000000 --- a/src/Javinizer/External/Logging/targets/Console.ps1 +++ /dev/null @@ -1,58 +0,0 @@ -@{ - Name = 'Console' - Description = 'Writes messages to console with different colors.' - Configuration = @{ - Level = @{Required = $false; Type = [string]; Default = $Logging.Level} - Format = @{Required = $false; Type = [string]; Default = $Logging.Format} - ColorMapping = @{Required = $false; Type = [hashtable]; Default = @{ - 'DEBUG' = 'Blue' - 'INFO' = 'Green' - 'WARNING' = 'Yellow' - 'ERROR' = 'Red' - } - } - } - Init = { - param( - [hashtable] $Configuration - ) - - foreach ($Level in $Configuration.ColorMapping.Keys) { - $Color = $Configuration.ColorMapping[$Level] - - if ($Color -notin ([System.Enum]::GetNames([System.ConsoleColor]))) { - $ParentHost.UI.WriteErrorLine("ERROR: Cannot use custom color '$Color': not a valid [System.ConsoleColor] value") - continue - } - } - } - Logger = { - param( - [hashtable] $Log, - [hashtable] $Configuration - ) - - try { - $logText = Replace-Token -String $Configuration.Format -Source $Log - - if (![String]::IsNullOrWhiteSpace($Log.ExecInfo)) { - $logText += "`n" + $Log.ExecInfo.InvocationInfo.PositionMessage - } - - $mtx = New-Object System.Threading.Mutex($false, 'ConsoleMtx') - [void] $mtx.WaitOne() - - if ($Configuration.ColorMapping.ContainsKey($Log.Level)) { - $ParentHost.UI.WriteLine($Configuration.ColorMapping[$Log.Level], $ParentHost.UI.RawUI.BackgroundColor, $logText) - } else { - $ParentHost.UI.WriteLine($logText) - } - - [void] $mtx.ReleaseMutex() - $mtx.Dispose() - } - catch { - $ParentHost.UI.WriteErrorLine($_) - } - } -} \ No newline at end of file diff --git a/src/Javinizer/External/Logging/targets/ElasticSearch.ps1 b/src/Javinizer/External/Logging/targets/ElasticSearch.ps1 deleted file mode 100644 index a405304c..00000000 --- a/src/Javinizer/External/Logging/targets/ElasticSearch.ps1 +++ /dev/null @@ -1,60 +0,0 @@ -@{ - Name = 'ElasticSearch' - Configuration = @{ - Index = @{Required = $true; Type = [string]; Default = $null} - Type = @{Required = $true; Type = [string]; Default = $null} - ServerName = @{Required = $true; Type = [string]; Default = $null} - ServerPort = @{Required = $true; Type = [int]; Default = 9200} - Flatten = @{Required = $false; Type = [bool]; Default = $false} - Level = @{Required = $false; Type = [string]; Default = $Logging.Level} - Authorization = @{Required = $false; Type = [string]; Default = $null} - Https = @{Required = $false; Type = [bool]; Default = $false} - } - Logger = { - param( - [hashtable] $Log, - [hashtable] $Configuration - ) - - Function ConvertTo-FlatterHashTable { - [CmdletBinding()] - param( - [hashtable] $Object - ) - - $ht = [hashtable] @{} - - foreach ($key in $Object.Keys) { - if ($Object[$key] -is [hashtable]) { - $ht += ConvertTo-FlatterHashTable -Object $Object[$key] - } else { - $ht[$key] = $Object[$key] - } - } - - return $ht - } - - if ($Configuration.Https) { - $httpType = "https" - } else { - $httpType = "http" - } - - $Index = Replace-Token -String $Configuration.Index -Source $Log - $Uri = '{0}://{1}:{2}/{3}/{4}' -f $httpType, $Configuration.ServerName, $Configuration.ServerPort, $Index, $Configuration.Type - - if ($Configuration.Flatten) { - $Message = ConvertTo-FlatterHashTable $Log | ConvertTo-Json -Compress - } else { - $Message = $Log | ConvertTo-Json -Compress - } - - if ($Configuration.Authorization) { - $base64Auth = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("$($Configuration.Authorization)"))) - Invoke-RestMethod -Method Post -Uri $Uri -Body $Message -Headers @{"Content-Type"="application/json";Authorization="Basic $base64Auth"} - } else { - Invoke-RestMethod -Method Post -Uri $Uri -Body $Message -Headers @{"Content-Type"="application/json"} - } - } -} \ No newline at end of file diff --git a/src/Javinizer/External/Logging/targets/Email.ps1 b/src/Javinizer/External/Logging/targets/Email.ps1 deleted file mode 100644 index e38321b1..00000000 --- a/src/Javinizer/External/Logging/targets/Email.ps1 +++ /dev/null @@ -1,41 +0,0 @@ -@{ - Name = 'Email' - Description = 'Send log message to email recipients' - Configuration = @{ - SMTPServer = @{Required = $true; Type = [string]; Default = $null} - From = @{Required = $true; Type = [string]; Default = $null} - To = @{Required = $true; Type = [string]; Default = $null} - Subject = @{Required = $false; Type = [string]; Default = '[%{level:-7}] %{message}'} - Credential = @{Required = $false; Type = [pscredential]; Default = $null} - Level = @{Required = $false; Type = [string]; Default = $Logging.Level} - Port = @{Required = $false; Type = [int]; Default = 25} - UseSsl = @{Required = $false; Type = [bool]; Default = $false} - Format = @{Required = $false; Type = [string]; Default = $Logging.Format} - } - Logger = { - param( - [hashtable] $Log, - [hashtable] $Configuration - ) - - $Params = @{ - SmtpServer = $Configuration.SMTPServer - From = $Configuration.From - To = $Configuration.To.Split(',').Trim() - Port = $Configuration.Port - UseSsl = $Configuration.UseSsl - Subject = Replace-Token -String $Configuration.Subject -Source $Log - Body = Replace-Token -String $Configuration.Format -Source $Log - } - - if ($Configuration.Credential) { - $Params['Credential'] = $Configuration.Credential - } - - if ($Log.Body) { - $Params.Body += "`n`n{0}" -f ($Log.Body | ConvertTo-Json) - } - - Send-MailMessage @Params - } -} diff --git a/src/Javinizer/External/Logging/targets/File.ps1 b/src/Javinizer/External/Logging/targets/File.ps1 deleted file mode 100644 index 682f8fcd..00000000 --- a/src/Javinizer/External/Logging/targets/File.ps1 +++ /dev/null @@ -1,34 +0,0 @@ -@{ - Name = 'File' - Configuration = @{ - Path = @{Required = $true; Type = [string]; Default = $null} - PrintBody = @{Required = $false; Type = [bool]; Default = $false} - Append = @{Required = $false; Type = [bool]; Default = $true} - Encoding = @{Required = $false; Type = [string]; Default = 'ascii'} - Level = @{Required = $false; Type = [string]; Default = $Logging.Level} - Format = @{Required = $false; Type = [string]; Default = $Logging.Format} - } - - Logger = { - param( - [hashtable] $Log, - [hashtable] $Configuration - ) - - if ($Configuration.PrintBody -and $Log.Body) { - $Log.Body = $Log.Body | ConvertTo-Json -Compress - } elseif (-not $Configuration.PrintBody -and $Log.Body) { - $Log.Remove('Body') - } - - $Text = Replace-Token -String $Configuration.Format -Source $Log - - $Params = @{ - Append = $Configuration.Append - FilePath = Replace-Token -String $Configuration.Path -Source $Log - Encoding = $Configuration.Encoding - } - - $Text | Out-File @Params - } -} \ No newline at end of file diff --git a/src/Javinizer/External/Logging/targets/Seq.ps1 b/src/Javinizer/External/Logging/targets/Seq.ps1 deleted file mode 100644 index e045618b..00000000 --- a/src/Javinizer/External/Logging/targets/Seq.ps1 +++ /dev/null @@ -1,33 +0,0 @@ -@{ - Name = 'Seq' - Description = 'Sends log data to the designated Seq server web service' - Configuration = @{ - Url = @{Required = $true; Type = [string]; Default = $null} - ApiKey = @{Required = $false; Type = [string]; Default = $null} - Properties = @{Required = $true; Type = [hashtable]; Default = $null} - Level = @{Required = $false; Type = [string]; Default = $Logging.Level} - } - Logger = { - param( - [hashtable] $Log, - [hashtable] $Configuration - ) - - $Body = @{ - Events = @(@{ - Timestamp = [System.DateTimeOffset]::Now.ToString('o') - Level = $Configuration.Level - MessageTemplate = $Log.Message | ConvertTo-Json - Properties = ($Log + $Configuration.Properties) | ConvertTo-Json - }) - } - - if ($Configuration.ApiKey) { - $Url = '{0}/api/events/raw?apiKey={1}' -f $Configuration.Url, $Configuration.ApiKey - } else { - $Url = '{0}/api/events/raw?' -f $Configuration.Url - } - - Invoke-RestMethod -Uri $Url -Body ($Body | ConvertTo-Json) -ContentType "application/json" -Method POST | Out-Null - } -} \ No newline at end of file diff --git a/src/Javinizer/External/Logging/targets/Slack.ps1 b/src/Javinizer/External/Logging/targets/Slack.ps1 deleted file mode 100644 index 0e1cb012..00000000 --- a/src/Javinizer/External/Logging/targets/Slack.ps1 +++ /dev/null @@ -1,37 +0,0 @@ -@{ - Name = 'Slack' - Configuration = @{ - WebHook = @{Required = $true; Type = [string]; Default = $null } - BotName = @{Required = $false; Type = [string]; Default = $null } - Channel = @{Required = $false; Type = [string]; Default = $null } - Icons = @{Required = $false; Type = [hashtable]; Default = @{ - 'ERROR' = ':fire:' - 'WARNING' = ':warning:' - 'INFO' = ':exclamation' - 'DEBUG' = ':eyes:' - } - } - Level = @{Required = $false; Type = [string]; Default = $Logging.Level} - Format = @{Required = $false; Type = [string]; Default = $Logging.Format} - } - Logger = { - param( - [hashtable] $Log, - [hashtable] $Configuration - ) - - $Text = @{ - text = Replace-Token -String $Configuration.Format -Source $Log - } - - if ($Configuration.BotName) { $Text['username'] = $Configuration.BotName } - - if ($Configuration.Channel) { $Text['channel'] = $Configuration.Channel } - - $Text['icon_emoji'] = $Configuration.Icons[$Log.LevelNo] - - $payload = 'payload={0}' -f ($Text | ConvertTo-Json -Compress) - - Invoke-RestMethod -Method POST -Uri $Configuration.WebHook -Body $payload | Out-Null - } -} diff --git a/src/Javinizer/External/Logging/targets/Teams.ps1 b/src/Javinizer/External/Logging/targets/Teams.ps1 deleted file mode 100644 index d88e37ee..00000000 --- a/src/Javinizer/External/Logging/targets/Teams.ps1 +++ /dev/null @@ -1,58 +0,0 @@ -@{ - Name = 'Teams' - Configuration = @{ - WebHook = @{Required = $true; Type = [string]; Default = $null } - Details = @{Required = $false; Type = [bool]; Default = $true} - Level = @{Required = $false; Type = [string]; Default = $Logging.Level} - Colors = @{Required = $false; Type = [hashtable]; Default = @{ - 'DEBUG' = 'blue' - 'INFO' = 'brightgreen' - 'WARNING' = 'orange' - 'ERROR' = 'red' - }} - } - Logger = { - param( - [hashtable] $Log, - [hashtable] $Configuration - ) - - $Payload = [ordered] @{ - '@type' = 'MessageCard' - '@context' = 'https://schema.org/extensions' - summary = '[{0}] {1}' -f $Log.Level, $Log.Message - themeColor = '#0078D7' - title = $Log.Message - text = '![{0}](https://raster.shields.io/static/v1?label=Logging&message={0}&color={1}&style=flat)' -f $Log.Level, $Configuration.Colors[$Log.Level] - } - - $sections = @() - - if ($Log.Body) { - $body = [ordered] @{} - $body.activitySubtitle = 'Body' - $body.text = $Log.Body | ConvertTo-Json -Depth 3 -Compress - $sections += $body - } - - if ($Configuration.Details) { - $details = [ordered] @{} - $details.activitySubtitle = 'Details' - $details.facts = $Log.Keys | ?{$_ -notin 'message', 'body'} | sort | %{ - [ordered] @{ - name = $_ - value = if ([string]::IsNullOrEmpty($Log[$_])) {'(none)'} else {[string] $Log[$_]} - } - } - $sections += $details - } - - if ($sections) { - $Payload.sections = $sections - } - - $Payload = $Payload | ConvertTo-Json -Depth 5 -Compress - - Invoke-RestMethod -Method POST -Uri $Configuration.WebHook -Body $Payload -ContentType 'application/json; charset=UTF-8' | Out-Null - } -} \ No newline at end of file diff --git a/src/Javinizer/External/Logging/targets/WebexTeams.ps1 b/src/Javinizer/External/Logging/targets/WebexTeams.ps1 deleted file mode 100644 index 770d1fd6..00000000 --- a/src/Javinizer/External/Logging/targets/WebexTeams.ps1 +++ /dev/null @@ -1,35 +0,0 @@ -@{ - Name = 'WebexTeams' - Configuration = @{ - BotToken = @{Required = $true; Type = [string]; Default = $null } - RoomID = @{Required = $true; Type = [string]; Default = $null } - Icons = @{Required = $false; Type = [hashtable]; Default = @{ - 'ERROR' = '🚨' - 'WARNING' = '⚠️' - 'INFO' = 'ℹ️' - 'DEBUG' = '🔎' - } - } - Level = @{Required = $false; Type = [string]; Default = $Logging.Level } - Format = @{Required = $false; Type = [string]; Default = $Logging.Format } - } - Logger = { - param( - [hashtable] $Log, - [hashtable] $Configuration - ) - # Build the Message body - $body = @{ - roomId = $Configuration.RoomId - text = $Configuration.Icons[$Log.Level] + " " + $(Replace-Token -String $Configuration.Format -Source $Log) - } - - # Convert to JSON - $json = $body | ConvertTo-Json - # Send Message to Cisco Webex API - UTF8 Handling for Emojiis - Invoke-RestMethod -Method Post ` - -Headers @{"Authorization" = "Bearer $($Configuration.BotToken)" } ` - -ContentType "application/json" -Body ([System.Text.Encoding]::UTF8.GetBytes($json)) ` - -Uri "https://api.ciscospark.com/v1/messages" - } -} diff --git a/src/Javinizer/External/Logging/targets/WinEventLog.ps1 b/src/Javinizer/External/Logging/targets/WinEventLog.ps1 deleted file mode 100644 index 491e1e59..00000000 --- a/src/Javinizer/External/Logging/targets/WinEventLog.ps1 +++ /dev/null @@ -1,50 +0,0 @@ -@{ - Name = 'WinEventLog' - Configuration = @{ - LogName = @{Required = $true; Type = [string]; Default = $null} - Source = @{Required = $true; Type = [string]; Default = $null} - Level = @{Required = $false; Type = [string]; Default = $Logging.Level} - } - Logger = { - param( - [hashtable] $Log, - [hashtable] $Configuration - ) - - $Params = @{ - EventId = 0 - } - - if ($Configuration.LogName) { $Params['LogName'] = $Configuration.LogName } - if ($Configuration.Source) { $Params['Source'] = $Configuration.Source } - if ($Log.Body.EventId) { $Params['EventId'] = $Log.Body.EventId } - - switch ($Log.LevelNo) { - {$_ -ge 40} { $Params['EntryType'] = 'Error' } - {$_ -ge 30 -and $_ -lt 40} { $Params['EntryType'] = 'Warning' } - {$_ -lt 30} { $Params['EntryType'] = 'Information' } - } - - $Params['Message'] = $Log.Message - - if ($Log.ExecInfo) { - $ExceptionFormat = "{0}`n" + - "{1}`n" + - "+ CategoryInfo : {2}`n" + - "+ FullyQualifiedErrorId : {3}`n" - - $ExceptionFields = @($Log.ExecInfo.Exception.Message, - $Log.ExecInfo.InvocationInfo.PositionMessage, - $Log.ExecInfo.CategoryInfo.ToString(), - $Log.ExecInfo.FullyQualifiedErrorId) - - if ( [string]::IsNullOrEmpty($Params['Message']) ){ - $Params['Message'] = $ExceptionFormat -f $ExceptionFields - } else { - $Params['Message'] += "`n`n" + ($ExceptionFormat -f $ExceptionFields) - } - } - - Write-EventLog @Params - } -} \ No newline at end of file