Reading log files
Another common structured text file format is log files. Log files consist of rows of logs, which are a line of text with a particular format, describing an event.
Logs are structured only in the same file or type of file. Formats can be very different and there's no common structure or syntax for them. Each application can and will use a different format.
Typically, each one will have a time when the event occurred, so the file is an ordered collection of them.
Getting ready
The example_log.log
file containing five sales logs can be obtained from the GitHub repository here: https://github.com/PacktPublishing/Python-Automation-Cookbook-Second-Edition/blob/master/Chapter04/documents/example_logs.log.
The format is:
[<Timestamp in iso format>] - SALE - PRODUCT: <product id> - PRICE: $<price of the sale>
We'll use the Chapter01/price_log.py
file to process each log into an object. There's a copy...