Sunday, December 16, 2018

Generic Log Parser (Filter By Log Dates–TimeZone, Log Expression) in Powershell

Find a Generic Log/Text Parser written in PowerShell here. This Parser allows filtering any kind of Logs (Windows Built in IIS, CBS or others) including Custom Logs from your application server environments. This parser also take the Time-Zone information into account, in which the Log Entries being written. The following are the key parameters by which Logs are being extracted;

a. Filter Start Log Date Time

b. Filter End Log Date Time

c. Time Zone in Which Filter Log (Above) have been given

d. Server Log Folders (network shares) from which logs will be parsed

e. An expression, which will be matched against log entries and only matching ones will be picked.

f. A print Time Zone, in which the dates of the selected Log Entries will be written to the output file

g. A Log Control File, which contains the structure of the Log File Formats.

e.g. Sample one given here, which defines the structure for the built in CBS and IIS Logs.

You could also define your own Log file formats from your environments and could include to this Control files. “LogEntryFormat” property of the Log Control entry, should contain three tokens namely DATE, TIME and ENTRY with the exact casing. These defines the positions in the Log entry to pick the Date, Time and the rest of the Log Entry to be parsed.

(Eg of Windows CBS Log: "LogEntryFormat": "(?<DATE>\\d{4,4}-\\d{1,2}-\\d{1,2}) (?<TIME>\\d+:\\d+:\\d+), (?<ENTRY>.*)")

A sample parsing can be found here.

To define a new Log Control entry for a custom log in your application environment, insert a similar entry to the Log Control Files and give it a unique name. The same should be specified for “logTypeControlKey” parameter. (e.g. ‘’logTypeControlKey = "CBS_LOG"”)



No comments:

Post a Comment