Skip to content

Commit

Permalink
Added Out-LogHost Function
Browse files Browse the repository at this point in the history
  • Loading branch information
guitarrapc committed Aug 13, 2013
1 parent 4b8e227 commit 7b24236
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions Out-LogHost/Out-LogHost.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
filter Out-LogHost{

param(
[string]
$logfile,

[switch]
$message,

[switch]
$showdata,

[switch]
$hidedata,

[switch]
$error
)


if($message)
{
Write-Host "$_`n" -ForegroundColor Cyan
"[$(Get-Date)][message][$_]" | Out-File $logfile -Encoding utf8 -Append -Width 1024
}
elseif($showdata)
{
$_
$_ | Out-File $logfile -Encoding utf8 -Append -Width 1024
}
elseif($hidedata)
{
$_ | Out-File $logfile -Encoding utf8 -Append -Width 1024
}
elseif($error)
{
$_ | Out-File $logfile -Encoding utf8 -Append -Width 1024
throw $_
}
}


$log = "d:\message.log"
"hogehoge" | Out-LogHost -logfile $log -message

$log = "d:\hidedata.log"
ps | select -First 1 | Out-LogHost -logfile $log -hidedata

$log = "d:\showdata.log"
ps | select -First 1 | Out-LogHost -logfile $log -showdata

$log = "d:\error.log"
try
{
ps -Name hoge -ErrorAction Stop
}
catch
{
$_ | Out-LogHost -logfile $log -error
}

0 comments on commit 7b24236

Please sign in to comment.