I\'ve got a powershell script that monitors a log file, filters out the interesting bits and then presents those bits to me as and when they are written to the file. Works w
If you're looking for something that provides selective color coding, then try something like this.
First, set up a helper function to select an appropriate color:
function Get-LogColor {
Param([Parameter(Position=0)]
[String]$LogEntry)
process {
if ($LogEntry.Contains("DEBUG")) {Return "Green"}
elseif ($LogEntry.Contains("WARN")) {Return "Yellow"}
elseif ($LogEntry.Contains("ERROR")) {Return "Red"}
else {Return "White"}
}
}
Then execute a line that looks like this:
gc -wait $logFile | ForEach {Write-Host -ForegroundColor (Get-LogColor $_) $_}
Try
Get-Content $logFile -Wait |
Select-String $searchTerm |
ForEach {write-host -ForegroundColor red $_.line}