From 1c034ff2509c9ee193f3e06313f4af48b7228dea Mon Sep 17 00:00:00 2001 From: Dmitry Teselkin Date: Wed, 27 Feb 2013 16:36:51 +0400 Subject: [PATCH] Log functions updated --- .../Modules/CoreFunctions/include/Logger.ps1 | 158 +++++++++--------- .../Modules/CoreFunctions/log4net.config | 72 ++++---- 2 files changed, 114 insertions(+), 116 deletions(-) diff --git a/Deployment/WindowsPowerShell/Modules/CoreFunctions/include/Logger.ps1 b/Deployment/WindowsPowerShell/Modules/CoreFunctions/include/Logger.ps1 index e04db7b8..9bcb6b75 100644 --- a/Deployment/WindowsPowerShell/Modules/CoreFunctions/include/Logger.ps1 +++ b/Deployment/WindowsPowerShell/Modules/CoreFunctions/include/Logger.ps1 @@ -24,115 +24,113 @@ [log4net.Config.XmlConfigurator]::Configure($Log4NetConfig) - $__Logger.info("Logger initialized. Log file: '$LogPath'") + $__Logger.info("Logger initialized. Log file: '$LogPath'`n") } - -Function Write-LogInfo { - param ( - [String[]] $Text - ) - foreach ($Line in $Text) { - $__Logger.info($Line) - } -} -New-Alias -Name Write-Log -Value Write-LogInfo - - - Function Out-LogInfo { - param ( - [Parameter(ValueFromPipeline=$true)] - [String] $Text - ) - $__Logger.info($Text) -} -New-Alias -Name Out-Log -Value Out-LogInfo - - - -Function Write-LogWarning { - param ( - [String] $Text - ) - foreach ($Line in $Text) { - $__Logger.warn($Line) + param ( + [Parameter(ValueFromPipeline=$true)] + $InputObject, + [Switch] $EntireObject + ) + process { + if ($EntireObject) { + $__Logger.info("`n$(Out-String -InputObject $InputObject)") + } + else { + foreach ($Object in $InputObject) { + $__Logger.info((Out-String -InputObject $Object)) + } + } } } +New-Alias -Name Out-Log -Value Out-LogInfo +New-Alias -Name Write-Log -Value Out-LogInfo Function Out-LogWarning { - param ( - [Parameter(ValueFromPipeline=$true)] - [String] $Text - ) - $__Logger__.warn($Text) -} - - - -Function Write-LogError { - param ( - [String] $Text - ) - foreach ($Line in $Text) { - $__Logger.error($Line) + param ( + [Parameter(ValueFromPipeline=$true)] + $InputObject, + [Switch] $EntireObject + ) + process { + if ($EntireObject) { + $__Logger.warn("`n$(Out-String -InputObject $InputObject)") + } + else { + foreach ($Object in $InputObject) { + $__Logger.warn((Out-String -InputObject $Object)) + } + } } } +New-Alias -Name Write-LogWarning -Value Out-LogWarning Function Out-LogError { - param ( - [Parameter(ValueFromPipeline=$true)] - [String] $Text - ) - $__Logger.error($Text) -} - - - -Function Write-LogFatal { - param ( - [String] $Text - ) - foreach ($Line in $Text) { - $__Logger.fatal($Line) + param ( + [Parameter(ValueFromPipeline=$true)] + $InputObject, + [Switch] $EntireObject + ) + process { + if ($EntireObject) { + $__Logger.error("`n$(Out-String -InputObject $InputObject)") + } + else { + foreach ($Object in $InputObject) { + $__Logger.error((Out-String -InputObject $Object)) + } + } } } +New-Alias -Name Write-LogError -Value Out-LogError Function Out-LogFatal { - param ( - [Parameter(ValueFromPipeline=$true)] - [String] $Text - ) - $__Logger.fatal($Text) -} - - - -Function Write-LogDebug { - param ( - [String] $Text - ) - foreach ($Line in $Text) { - $__Logger.debug($Line) + param ( + [Parameter(ValueFromPipeline=$true)] + $InputObject, + [Switch] $EntireObject + ) + process { + if ($EntireObject) { + $__Logger.fatal("`n$(Out-String -InputObject $InputObject)") + } + else { + foreach ($Object in $InputObject) { + $__Logger.fatal((Out-String -InputObject $Object)) + } + } } } +New-Alias -Name Write-LogFatal -Value Out-LogFatal Function Out-LogDebug { - param ( - [Parameter(ValueFromPipeline=$true)] - [String] $Text - ) - $__Logger.debug($Text) + param ( + [Parameter(ValueFromPipeline=$true)] + $InputObject, + [Switch] $EntireObject + ) + process { + if ($EntireObject) { + $__Logger.debug("`n$(Out-String -InputObject $InputObject)") + } + else { + foreach ($Object in $InputObject) { + $__Logger.debug((Out-String -InputObject $Object)) + } + } + } } +New-Alias -Name Write-LogDebug -Value Out-LogDebug diff --git a/Deployment/WindowsPowerShell/Modules/CoreFunctions/log4net.config b/Deployment/WindowsPowerShell/Modules/CoreFunctions/log4net.config index ea7aa0e3..1b0b20bc 100644 --- a/Deployment/WindowsPowerShell/Modules/CoreFunctions/log4net.config +++ b/Deployment/WindowsPowerShell/Modules/CoreFunctions/log4net.config @@ -1,42 +1,42 @@  - - - - - - - - - - - - + + + + + + + + + + + + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - + - - - + + + - + \ No newline at end of file