3_logparse module¶
Log parser¶
Accepts a filename on the command line. The file is a Linux-like log file from a system you are debugging. Mixed in among the various statements are messages indicating the state of the device. They look like this:
Jul 11 16:11:51:490 [139681125603136] dut: Device State: ON
The device state message has many possible values, but this program cares
about only three: ON, OFF, and ERR.
Your program will parse the given log file and print out
a report giving how long the device was ON
and the timestamp of any ERR conditions.
-
3_logparse.check_errors(filtered_log: List[Tuple[datetime.datetime, str]]) → List[str][source]¶ Get the timestamps associated with the status
ERR.- Parameters
filtered_log (typing.List[typing.Tuple[datetime.datetime, str]]) – list of tuples with timestamp and status.
- Returns
list of timestamps formatted to nice strings.
- Return type
typing.List[str]
-
3_logparse.cli_parse() → pathlib.Path[source]¶ CLI interface to get the logfile path with the
--logargument.- Returns
path of the logfile.
- Return type
pathlib.Path
-
3_logparse.compute_uptime(filtered_log: List[Tuple[datetime.datetime, str]]) → float[source]¶ Compute the total uptime in seconds between each
ONandOFFstatus.- Parameters
filtered_log (typing.List[typing.Tuple[datetime.datetime, str]]) – list of tuples with timestamp and status.
- Returns
seconds of uptime.
- Return type
float
-
3_logparse.filter_log(log: pathlib.Path) → List[Tuple[datetime.datetime, str]][source]¶ Read the logfile and get the timestamp and the status of log messages reporting the Device status.
- Parameters
log (pathlib.Path) – file path of the logfile.
- Returns
list of tuples with timestamp and status.
- Return type
typing.List[typing.Tuple[datetime.datetime, str]]