Using PowerShell to Parse Log Files

This is a very short and sweet blog on a neat few lines of PowerShell I have been using to help focus on what matters in the output The D.R.G. Initiative creates.

$AbsoluteFilePath = "C:\SomeLogFileFromYourGame.log"
if([System.IO.File]::Exists($AbsoluteFilePath))
{ 
    gc $AbsoluteFilePath -wait | where {($_ -match "Error") -or ($_ -match "Assert"))} | Tee-Object -file "C:\SomeOutputFile.customlog"
}

That’s it!

Bang this in PowerShell, point it at where your logs are generated, and off you go. The code snippet uses gc (Get-Content) to parse the data, then Tee-Object to pipe any line with “Assert” or “Error” into the console and an output file. Obviously, there is loads more you can do with this but I was just aiming for the bare minimum to make my life a little easier. In my opinion this is about as simple as it gets!

Alternatively, check out the very awesome BareTail application for a great logging tool.

For more logging tips see also

Bark at the Moon: Better Lua Logging

User Defined Languages in Notepad++

Leave a Reply