Skip to content
Browse files

Added ability to set a 'Tag' in the 'Set-LogParameters' so that logge…

…d messages can be more easily identified
  • Loading branch information...
1 parent 649424b commit 35809e982d91d48cbb289000f7c7980c199cc315 @russellseymour committed Mar 10, 2014
View
10 functions/exported/Set-LogParameters.ps1
@@ -57,6 +57,11 @@ function Set-LogParameters {
# If not set this item will not appear in the logging object
$custom = $false,
+ [Parameter(ParameterSetName="switches")]
+ # Tag
+ # Tag that should be prepended to any log messahe
+ $tag,
+
[Parameter(ParameterSetName="object")]
# Parameters
# This is an object that contains all of the settings that need to be defined in the module
@@ -116,6 +121,11 @@ function Set-LogParameters {
$Logging.custom = $custom
}
+ # Add the tag to the sessting
+ if (!($Logging.ContainsKey("tag")) -and ![String]::IsNullOrEmpty($tag)) {
+ $Logging.tag = $tag
+ }
+
}
"object" {
View
10 functions/exported/Write-Log.ps1
@@ -36,7 +36,7 @@ function Write-Log {
# variable to hold extra information to be added to the message
# this is how default messages can be enchances
$extra = $false,
-
+
#region Write-Host Parameters
[Parameter(ParameterSetName="Host")]
@@ -185,6 +185,12 @@ function Write-Log {
}
$provider_paths += "{0}\providers" -f $module_path
+ # determine if a tag has been specified in the session
+ if (![String]::IsNullOrEmpty($script:Logging.tag)) {
+ $logtag = $script:Logging.tag
+ } elseif (![String]::IsNullOrEmpty($LogTagPreference)) {
+ $logtag = $LogTagPreference
+ }
}
@@ -194,7 +200,7 @@ function Write-Log {
$resource = Load-Help -Path $resource
# Find the message from the eventid and return as a message object
- $msg, $formatting = Get-HelpMessage -EventId $EventId -Resource $resource -Message $Object -ForegroundColor $ForegroundColor -BackgroundColor $BackgroundColor -Prepend $Prepend
+ $msg, $formatting = Get-HelpMessage -EventId $EventId -Resource $resource -Message $Object -ForegroundColor $ForegroundColor -BackgroundColor $BackgroundColor -Prepend $Prepend -Tag $logtag
# Get the message structure to work with
$structure = Format-Message -Level $level -EventId $EventId -Message $msg -Severity $severity
View
6 functions/resources/Get-HelpMessage.ps1
@@ -42,7 +42,10 @@ function Get-HelpMessage {
# Ensure that the colours from the calling function are pulled in
$ForegroundColor,
- $BackgroundColor
+ $BackgroundColor,
+
+ # the log tag that has been supplied
+ $tag
)
@@ -57,6 +60,7 @@ function Get-HelpMessage {
foregroundcolor = $ForegroundColor
backgroundcolor = $BackgroundColor
prepend = $prepend
+ tag = $tag
}
if ($resource -ne $false) {
View
6 providers/LogFile.ps1
@@ -39,7 +39,11 @@ function Set-Message {
# if there are results add the information tot heline
if ($results.count -gt 0 -and ($prependString = $results[0]) -is [System.String])
{
- $line = "{0} - {1} - {2} - {3}" -f $prependString, $structure.severity, $structure.eventid, $line
+ if ([String]::IsNullOrEmpty($formatting.tag)) {
+ $line = "{0} - {1} - {2} - {3}" -f $prependString, $structure.severity, $structure.eventid, $line
+ } else {
+ $line = "{0} - {1} - {2} - {3} - {4}" -f $prependString, $structure.severity, $structure.eventid, $formatting.tag, $line
+ }
}
}

0 comments on commit 35809e9

Please sign in to comment.
Something went wrong with that request. Please try again.